From 81bb4ef30075313ff4b87e2745e3ace64e04bfa9 Mon Sep 17 00:00:00 2001 From: Zicklag Date: Mon, 11 Jul 2022 14:11:27 +0000 Subject: [PATCH] Document That FloatOrd Implements Hash and Eq Too (#5228) # Objective - Slight documentation tweak to make it more clear that `FloatOrd` also implements `Hash` and `Eq`, not just `Ord`. - I know that it does show that Hash is implemented in the docs, but I had missed it after reading the description and assuming it didn't do it, so hopefully this helps other people who might miss it like I did. :) ## Solution - Just mention in the Hash and Eq implementation in the docstring. --- crates/bevy_utils/src/float_ord.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/bevy_utils/src/float_ord.rs b/crates/bevy_utils/src/float_ord.rs index 45832198ad..9e7931d220 100644 --- a/crates/bevy_utils/src/float_ord.rs +++ b/crates/bevy_utils/src/float_ord.rs @@ -4,9 +4,15 @@ use std::{ ops::Neg, }; -/// A wrapper type that enables ordering floats. This is a work around for the famous "rust float -/// ordering" problem. By using it, you acknowledge that sorting NaN is undefined according to spec. -/// This implementation treats NaN as the "smallest" float. +/// 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`. +/// +/// 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`. #[derive(Debug, Copy, Clone, PartialOrd)] pub struct FloatOrd(pub f32);