diff --git a/crates/bevy_core/src/float_ord.rs b/crates/bevy_core/src/float_ord.rs index 74496b7756..2958e83857 100644 --- a/crates/bevy_core/src/float_ord.rs +++ b/crates/bevy_core/src/float_ord.rs @@ -40,7 +40,15 @@ impl Eq for FloatOrd {} impl Hash for FloatOrd { fn hash(&self, state: &mut H) { - state.write(self.0.as_bytes()); + 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()); + } } }