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
Primitive operations on floating-point types generally produce results that exactly match IEEE 754-2008:
34
-
if you never use `to_bits`, `copysign`, `is_sign_negative`, or `is_sign_positive` on a NaN, and don't construct a NaN using `from_bits`, nor use any unsafe operations that are equivalent to these safe methods, then your code will behave perfectly deterministically and according to the IEEE specification.
34
+
if you never use `to_bits`, `copysign`, `is_sign_negative`, or `is_sign_positive` on a NaN, and don't construct a NaN using `from_bits`, nor use any unsafe operations that are equivalent to these safe methods, then your code will not be able to observe any non-determinism and behave according to the IEEE specification.
35
35
36
36
If you *do* use these operations on NaNs, then the exact behavior you see can depend on compiler version, compiler flags, target architecture, and it can even be non-deterministic (i.e., running the same operation on the same inputs twice can yield different results).
37
37
The results produced in these cases do *not* always conform to the IEEE specification.
@@ -67,7 +67,7 @@ the result has a non-deterministic sign; the quiet bit and payload are non-deter
67
67
- The quiet bit is set and the payload is all-zero. ("Preferred NaN" case)
68
68
- The quiet bit is set and the payload is copied from any input operand that is a NaN.
69
69
("Quieting NaN propagation" case) <br>
70
-
If the inputs and outputs do not have the same size (i.e., for `as` casts), then
70
+
If the inputs and outputs do not have the same payload size (i.e., for `as` casts), then
71
71
- If the output is smaller than the input, low-order bits of the payload get dropped.
72
72
- If the output is larger than the input, the payload gets filled up with 0s in the low-order bits.
73
73
- The quiet bit and payload are copied from any input operand that is a NaN.
@@ -120,9 +120,9 @@ When the RFC is accepted, the `const_fn_floating_point_arithmetic` feature gate
120
120
This RFC is primarily concerned with the guarantee Rust provides to its users.
121
121
How exactly those guarantees are achieved is an implementation detail, and not observable when writing pure Rust code.
122
122
However, when mixing Rust with inline assembly, those details *do* become observable.
123
-
To ensure that Rust can provide the above guarantees to user code, it is UB for inline assembly to alter the behavior of floating-point operations in any way: when leaving the inline assembly block, the floating-point environment must be in exactly the same state as when the inline assembly block was entered.
123
+
To ensure that Rust can provide the above guarantees to user code, it is UB for inline assembly to alter the behavior of floating-point operations in any way: when leaving the inline assembly block, the floating-point control bits must be in exactly the same state as when the inline assembly block was entered.
124
124
This is just an instance of the general principle that it is UB for inline assembly to violate any of the invariants that the Rust compiler relies on when implementing Rust semantics on the target hardware.
125
-
Furthermore, observing the floating-point exception state yields entirely unspecified results: Rust floating-point operations may or may not be executed at the place in the code where they were originally written, and the exception state can change even if no floating-point operation exists in the source code.
125
+
Furthermore, observing the floating-point exception state yields entirely unspecified results: Rust floating-point operations may or may not be executed at the place in the code where they were originally written, and the floating-point status bits can change even if no floating-point operation exists in the source code.
126
126
127
127
(This is very similar to C without `#pragma STD FENV_ACCESS`.)
0 commit comments