You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
on an ARM64 machine running macOS and on an x86-64 machine running Linux.
This code is adding +infinity + -infinity and producing a NaN.
I expected to see the same output on both systems.
Instead, the sign of the returned NaN differs between the two systems.
On ARM64, I get,
$ cargo +nightly run --quiet0x7c00 + 0xfc00 = 0x7e00
On x86-64, I get,
$ cargo +nightly run --quiet0x7c00 + 0xfc00 = 0xfe00
As you can see, the only difference is in the NaN's sign bit.
As I read IEEE 754-2008, §6.3, the sign bit of a NaN is not meaningful and that for addition (and most operations), the standard "does not specify the sign bit of a NaN result."
So in the sense of following the standard, this isn't a bug. But it might be nice to produce the same values on supported platforms. Of course, if hardware implementations differ, there's nothing to do.
If I change the code to this
let pos_inf = f32::INFINITY;let neg_inf = -f32::INFINITY;let sum = pos_inf + neg_inf;println!("{:08x} + {:08x} = {:08x}", pos_inf.to_bits(), neg_inf.to_bits(), sum.to_bits());
As I read IEEE 754-2008, §6.3, the sign bit of a NaN is not meaningful and that for addition (and most operations), the standard "does not specify the sign bit of a NaN result."
I tried this code:
on an ARM64 machine running macOS and on an x86-64 machine running Linux.
This code is adding +infinity + -infinity and producing a NaN.
I expected to see the same output on both systems.
Instead, the sign of the returned NaN differs between the two systems.
On ARM64, I get,
On x86-64, I get,
As you can see, the only difference is in the NaN's sign bit.
As I read IEEE 754-2008, §6.3, the sign bit of a NaN is not meaningful and that for addition (and most operations), the standard "does not specify the sign bit of a NaN result."
So in the sense of following the standard, this isn't a bug. But it might be nice to produce the same values on supported platforms. Of course, if hardware implementations differ, there's nothing to do.
If I change the code to this
then I get the same output for both systems:
Meta
The text was updated successfully, but these errors were encountered: