Fix FloatOrd hash being different for different NaN values (#618)
* Fix FloatOrd hash being different for different NaN values * Fix FloatOrd hashing +0.0 and -0.0 to different values
This commit is contained in:
parent
22a2c88a47
commit
9a4167ef7f
@ -40,8 +40,16 @@ impl Eq for FloatOrd {}
|
||||
|
||||
impl Hash for FloatOrd {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
if self.0.is_nan() {
|
||||
// Ensure all NaN representations hash to the same value
|
||||
state.write(f32::NAN.as_bytes())
|
||||
} else if self.0 == 0.0 {
|
||||
// Ensure both zeroes hash to the same value
|
||||
state.write(0.0f32.as_bytes())
|
||||
} else {
|
||||
state.write(self.0.as_bytes());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Neg for FloatOrd {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user