@@ -70,12 +70,26 @@ fn canonicalize_signed_zero<T: FloatCore>(x: T) -> T {
70
70
/// # use ordered_float::OrderedFloat;
71
71
/// # use std::collections::HashSet;
72
72
/// # use std::f32::NAN;
73
- ///
74
73
/// let mut s: HashSet<OrderedFloat<f32>> = HashSet::new();
75
74
/// s.insert(OrderedFloat(NAN));
76
75
/// assert!(s.contains(&OrderedFloat(NAN)));
77
76
/// ```
78
77
///
78
+ /// Some non-identical values are still considered equal by the [`PartialEq`] implementation,
79
+ /// and will therefore also be considered equal by maps, sets, and the `==` operator:
80
+ ///
81
+ /// * `-0.0` and `+0.0` are considered equal.
82
+ /// This different sign may show up in printing, or when dividing by zero (the sign of the zero
83
+ /// becomes the sign of the resulting infinity).
84
+ /// * All NaN values are considered equal, even though they may have different
85
+ /// [bits](https://doc.rust-lang.org/std/primitive.f64.html#method.to_bits), and therefore
86
+ /// different [sign](https://doc.rust-lang.org/std/primitive.f64.html#method.is_sign_positive),
87
+ /// signaling/quiet status, and NaN payload bits.
88
+ ///
89
+ /// Therefore, `OrderedFloat` may be unsuitable for use as a key in interning and memoization
90
+ /// applications which require equal results from equal inputs, unless these cases make no
91
+ /// difference or are canonicalized before insertion.
92
+ ///
79
93
/// # Representation
80
94
///
81
95
/// `OrderedFloat` has `#[repr(transparent)]` and permits any value, so it is sound to use
@@ -1152,13 +1166,18 @@ impl<T: FloatCore + Num> Num for OrderedFloat<T> {
1152
1166
/// ```
1153
1167
/// # use ordered_float::NotNan;
1154
1168
/// # use std::collections::HashSet;
1155
- ///
1156
1169
/// let mut s: HashSet<NotNan<f32>> = HashSet::new();
1157
1170
/// let key = NotNan::new(1.0).unwrap();
1158
1171
/// s.insert(key);
1159
1172
/// assert!(s.contains(&key));
1160
1173
/// ```
1161
1174
///
1175
+ /// `-0.0` and `+0.0` are still considered equal. This different sign may show up in printing,
1176
+ /// or when dividing by zero (the sign of the zero becomes the sign of the resulting infinity).
1177
+ /// Therefore, `NotNan` may be unsuitable for use as a key in interning and memoization
1178
+ /// applications which require equal results from equal inputs, unless signed zeros make no
1179
+ /// difference or are canonicalized before insertion.
1180
+ ///
1162
1181
/// Arithmetic on NotNan values will panic if it produces a NaN value:
1163
1182
///
1164
1183
/// ```should_panic
0 commit comments