rust-lang / unsafe-code-guidelines

Forum for discussion about what unsafe code can and can't do
https://rust-lang.github.io/unsafe-code-guidelines
Apache License 2.0
660 stars 57 forks source link

Our floating point semantics were a mess #237

Closed RalfJung closed 2 months ago

RalfJung commented 4 years ago

Floating-point semantics are hard, in particular the NaN part, but this should describe them accurately -- except on x86-32, for more than one reason.

We still need to officially decide that those are our intended semantics though. https://github.com/rust-lang/rust/issues/73328 tracks that on the rustc side.

Historic info There are several ways in which our de-facto FP semantics currently are broken: * LLVM doesn't preserve NaN bits (which is likely incoherent). That's https://github.com/rust-lang/rust/issues/73328, which is a meta-issue. Specific issues: rust-lang/rust#55131 (on all platforms) * LLVM uses the x87 instructions and registers on i686 which behave different from how IEEE floats should behave. That's https://github.com/rust-lang/rust/issues/72327 (without SSE2) and https://github.com/rust-lang/rust/issues/73288 (with SSE2). * LLVM does not distinguish sNaN and qNaN the way IEEE mandates: https://github.com/rust-lang/rust/issues/107247. I'm adding this here because figuring out the semantics of Rust is part of the goal of the UCG (I think?) and we should have an overarching "FP semantics" tracker *somewhere*.
RalfJung commented 1 year ago

The RFC https://github.com/rust-lang/rfcs/pull/3514 should resolve all questions for good. :)

RalfJung commented 2 months ago

Superseded by https://github.com/rust-lang/rust/issues/128288, now that the RFC got accepted!