Skip to content
Closed
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
51 changes: 51 additions & 0 deletions tests/d2s_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,54 @@ fn test_small_integers() {
check!(549755813888000.0);
check!(8796093022208000.0);
}
#[test]
fn test_boundary_values() {
// Subnormal/normal boundary near f64::MIN_POSITIVE
check!(2.225073858507201e-308); // largest subnormal
check!(2.2250738585072014e-308); // smallest positive normal
check!(2.225073858507202e-308); // just above smallest positive normal

// Neighbors of powers of two
check!(0.49999999999999994);
check!(0.5);
check!(0.5000000000000001);
check!(0.9999999999999999);
check!(1.0);
check!(1.0000000000000002);
check!(1.9999999999999998);
check!(2.0);
check!(2.0000000000000004);
check!(3.9999999999999996);
check!(4.0);
check!(4.000000000000001);

// Negative counterparts
check!(-0.49999999999999994);
check!(-2.225073858507201e-308);
check!(-4.000000000000001);

// Round-trip parse-back assertions
let mut buf = ryu::Buffer::new();
for f in [
2.225073858507201e-308,
2.2250738585072014e-308,
2.225073858507202e-308,
0.49999999999999994,
0.5,
0.5000000000000001,
0.9999999999999999,
1.0,
1.0000000000000002,
1.9999999999999998,
2.0,
2.0000000000000004,
3.9999999999999996,
4.0,
4.000000000000001,
-0.49999999999999994,
-2.225073858507201e-308,
-4.000000000000001,
] {
assert_eq!(f, buf.format(f).parse().unwrap());
}
}
22 changes: 22 additions & 0 deletions tests/s2d_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,25 @@ fn test_issue173() {
s2d(b"2.2250738585072014e-308").unwrap(),
);
}

#[test]
fn test_boundary() {
// Subnormal/normal boundary near f64::MIN_POSITIVE
assert_eq!(f64::from_bits(0x000FFFFFFFFFFFFF), s2d(b"2.225073858507201e-308").unwrap());
assert_eq!(f64::MIN_POSITIVE, s2d(b"2.2250738585072014e-308").unwrap());
assert_eq!(f64::from_bits(0x0010000000000001), s2d(b"2.225073858507202e-308").unwrap());

// Neighbors of powers of two
assert_eq!(f64::from_bits(0x3FDFFFFFFFFFFFFF), s2d(b"0.49999999999999994").unwrap());
assert_eq!(0.5, s2d(b"0.5").unwrap());
assert_eq!(f64::from_bits(0x3FE0000000000001), s2d(b"0.5000000000000001").unwrap());
assert_eq!(f64::from_bits(0x3FEFFFFFFFFFFFFF), s2d(b"0.9999999999999999").unwrap());
assert_eq!(1.0, s2d(b"1.0").unwrap());
assert_eq!(f64::from_bits(0x3FF0000000000001), s2d(b"1.0000000000000002").unwrap());
assert_eq!(f64::from_bits(0x3FFFFFFFFFFFFFFF), s2d(b"1.9999999999999998").unwrap());
assert_eq!(2.0, s2d(b"2.0").unwrap());
assert_eq!(f64::from_bits(0x4000000000000001), s2d(b"2.0000000000000004").unwrap());
assert_eq!(f64::from_bits(0x400FFFFFFFFFFFFF), s2d(b"3.9999999999999996").unwrap());
assert_eq!(4.0, s2d(b"4.0").unwrap());
assert_eq!(f64::from_bits(0x4010000000000001), s2d(b"4.000000000000001").unwrap());
}