Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions crates/bevy_math/src/float_ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ use bevy_reflect::Reflect;

/// A wrapper for floats that implements [`Ord`], [`Eq`], and [`Hash`] traits.
///
/// This is a work around for the fact that the IEEE 754-2008 standard,
/// implemented by Rust's [`f32`] type,
/// doesn't define an ordering for [`NaN`](f32::NAN),
/// and `NaN` is not considered equal to any other `NaN`.
/// Particularly useful if you want to sort floats or use them as part of map keys.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is independent of the main change; I don't have a strong opinion on adding it.

///
/// Wrapping a float with `FloatOrd` breaks conformance with the standard
/// by sorting `NaN` as less than all other numbers and equal to any other `NaN`.
/// Floats in Rust follow the IEEE 754-2008 standard, the comparison operators
/// of which are not defined when at least one of the operands are [`NaN`](f32::NAN).
///
/// `FloatOrd` defines an ordering for those cases by sorting all `NaN`s as less than all
/// numbers and as equal to any other `NaN`.
///
/// `FloatOrd` is incompatible with the `totalOrder` predicate defined by IEEE 754,
/// but stays consistent with normal float comparison: If a `a.partial_cmp(b)` is `Some`,
/// the result is the same for `FloatOrd(a).cmp(FloatOrd(b))`.
#[derive(Debug, Copy, Clone, Default)]
#[cfg_attr(
feature = "bevy_reflect",
Expand Down