Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@
impl<T: FloatCore> PartialEq<T> for OrderedFloat<T> {
#[inline]
fn eq(&self, other: &T) -> bool {
self.0 == *other
<OrderedFloat<T> as PartialEq>::eq(self, &OrderedFloat(*other))
}
}

Expand Down Expand Up @@ -2269,7 +2269,7 @@
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
let float = T::deserialize(d)?;
NotNan::new(float).map_err(|_| {
Error::invalid_value(Unexpected::Float(f64::NAN), &"float (but not NaN)")

Check failure on line 2272 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Tests (stable)

use of deprecated constant `core::f64::NAN`: replaced by the `NAN` associated constant on `f64`

Check warning on line 2272 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Tests (stable)

use of deprecated constant `core::f64::NAN`: replaced by the `NAN` associated constant on `f64`
})
}
}
Expand All @@ -2289,7 +2289,7 @@
#[test]
fn test_fail_on_nan() {
assert_de_tokens_error::<NotNan<f64>>(
&[Token::F64(f64::NAN)],

Check failure on line 2292 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Tests (stable)

use of deprecated constant `core::f64::NAN`: replaced by the `NAN` associated constant on `f64`
"invalid value: floating point `NaN`, expected float (but not NaN)",
);
}
Expand Down
54 changes: 54 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
#[test]
fn test_total_order() {
let numberline = [
(-f32::INFINITY, 0),

Check warning on line 27 in tests/test.rs

View workflow job for this annotation

GitHub Actions / Tests (stable)

use of deprecated constant `std::f32::INFINITY`: replaced by the `INFINITY` associated constant on `f32`
(-1.0, 1),
(-0.0, 2),
(0.0, 2),
(1.0, 3),
(f32::INFINITY, 4),

Check warning on line 32 in tests/test.rs

View workflow job for this annotation

GitHub Actions / Tests (stable)

use of deprecated constant `std::f32::INFINITY`: replaced by the `INFINITY` associated constant on `f32`
(f32::NAN, 5),

Check warning on line 33 in tests/test.rs

View workflow job for this annotation

GitHub Actions / Tests (stable)

use of deprecated constant `std::f32::NAN`: replaced by the `NAN` associated constant on `f32`
(-f32::NAN, 5),

Check warning on line 34 in tests/test.rs

View workflow job for this annotation

GitHub Actions / Tests (stable)

use of deprecated constant `std::f32::NAN`: replaced by the `NAN` associated constant on `f32`
];

for &(fi, i) in &numberline {
Expand Down Expand Up @@ -98,13 +98,67 @@
assert!(f32_nan >= OrderedFloat(<f32 as FloatCore>::neg_infinity()));
}

#[test]
fn ordered_f32_mixed_eq_controls() {
assert!(OrderedFloat(1.0f32) == 1.0);
assert!(OrderedFloat(1.0f32) != 2.0);
assert!(OrderedFloat(f32::INFINITY) == f32::INFINITY);

Check warning on line 105 in tests/test.rs

View workflow job for this annotation

GitHub Actions / Tests (stable)

use of deprecated constant `std::f32::INFINITY`: replaced by the `INFINITY` associated constant on `f32`

Check warning on line 105 in tests/test.rs

View workflow job for this annotation

GitHub Actions / Tests (stable)

use of deprecated constant `std::f32::INFINITY`: replaced by the `INFINITY` associated constant on `f32`
assert!(OrderedFloat(f32::NEG_INFINITY) == f32::NEG_INFINITY);

Check warning on line 106 in tests/test.rs

View workflow job for this annotation

GitHub Actions / Tests (stable)

use of deprecated constant `std::f32::NEG_INFINITY`: replaced by the `NEG_INFINITY` associated constant on `f32`

Check warning on line 106 in tests/test.rs

View workflow job for this annotation

GitHub Actions / Tests (stable)

use of deprecated constant `std::f32::NEG_INFINITY`: replaced by the `NEG_INFINITY` associated constant on `f32`
assert!(OrderedFloat(f32::INFINITY) != f32::NEG_INFINITY);

Check warning on line 107 in tests/test.rs

View workflow job for this annotation

GitHub Actions / Tests (stable)

use of deprecated constant `std::f32::INFINITY`: replaced by the `INFINITY` associated constant on `f32`
assert!(OrderedFloat(0.0f32) == -0.0);
assert!(OrderedFloat(-0.0f32) == 0.0);
}

#[test]
fn ordered_f32_mixed_eq_nan() {
let first = f32::from_bits(0x7fc0_0001);
let second = f32::from_bits(0xffc0_0002);

assert!(OrderedFloat(first) == OrderedFloat(second));
assert!(OrderedFloat(first) == first);
assert!(OrderedFloat(second) == first);
assert!(!(OrderedFloat(first) != first));
assert!(!(OrderedFloat(second) != first));
assert!(OrderedFloat(first) != 1.0);
assert!(OrderedFloat(1.0f32) != first);
assert!(OrderedFloat(first) != f32::INFINITY);
assert!(OrderedFloat(f32::INFINITY) != first);
}

#[test]
fn ordered_f64_compare_regular_floats() {
assert_eq!(OrderedFloat(7.0f64).cmp(&OrderedFloat(7.0)), Equal);
assert_eq!(OrderedFloat(8.0f64).cmp(&OrderedFloat(7.0)), Greater);
assert_eq!(OrderedFloat(4.0f64).cmp(&OrderedFloat(7.0)), Less);
}

#[test]
fn ordered_f64_mixed_eq_controls() {
assert!(OrderedFloat(1.0f64) == 1.0);
assert!(OrderedFloat(1.0f64) != 2.0);
assert!(OrderedFloat(f64::INFINITY) == f64::INFINITY);
assert!(OrderedFloat(f64::NEG_INFINITY) == f64::NEG_INFINITY);
assert!(OrderedFloat(f64::INFINITY) != f64::NEG_INFINITY);
assert!(OrderedFloat(0.0f64) == -0.0);
assert!(OrderedFloat(-0.0f64) == 0.0);
}

#[test]
fn ordered_f64_mixed_eq_nan() {
let first = f64::from_bits(0x7ff8_0000_0000_0001);
let second = f64::from_bits(0xfff8_0000_0000_0002);

assert!(OrderedFloat(first) == OrderedFloat(second));
assert!(OrderedFloat(first) == first);
assert!(OrderedFloat(second) == first);
assert!(!(OrderedFloat(first) != first));
assert!(!(OrderedFloat(second) != first));
assert!(OrderedFloat(first) != 1.0);
assert!(OrderedFloat(1.0f64) != first);
assert!(OrderedFloat(first) != f64::INFINITY);
assert!(OrderedFloat(f64::INFINITY) != first);
}

/// This code is not run, but successfully compiling it checks that the given bounds
/// are *sufficient* to write code that is generic over float type.
fn _generic_code_can_use_float_core<T>(inputs: &mut [OrderedFloat<T>])
Expand Down
Loading