mirror of
https://github.com/FliegendeWurst/ieee754-interpreter.git
synced 2024-11-22 05:44:57 +00:00
Parse infinity correctly
This commit is contained in:
parent
9b835a7ebe
commit
d0edb4db77
@ -49,7 +49,7 @@ fn interpret_single(float: u32) -> f32 {
|
|||||||
if mantissa != 0 {
|
if mantissa != 0 {
|
||||||
return f32::NAN;
|
return f32::NAN;
|
||||||
} else {
|
} else {
|
||||||
return sign * f32::INFINITY;
|
return f32::INFINITY.copysign(sign);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,6 +72,8 @@ fn interpret_single_test() {
|
|||||||
(0b1011_1111_0101_0000_0000_0000_0000_0000, -0.8125),
|
(0b1011_1111_0101_0000_0000_0000_0000_0000, -0.8125),
|
||||||
// denormalized float
|
// denormalized float
|
||||||
(0b0000_0000_0100_0000_0000_0000_0000_0000, 0.000000000000000000000000000000000000005877472),
|
(0b0000_0000_0100_0000_0000_0000_0000_0000, 0.000000000000000000000000000000000000005877472),
|
||||||
|
// positive infinity
|
||||||
|
(0b0_1111_1111_00000000000000000000000, f32::INFINITY),
|
||||||
];
|
];
|
||||||
// some sanity checks around subnormals
|
// some sanity checks around subnormals
|
||||||
assert_eq!(2.0f32.powi(-127), tests[2].1);
|
assert_eq!(2.0f32.powi(-127), tests[2].1);
|
||||||
|
Loading…
Reference in New Issue
Block a user