Skip to content

Floating point comparisons in Rust do not follow IEEE 754 #1084

Closed
@mbrubeck

Description

@mbrubeck

For example, (NaN == NaN) is true in Rust but false in IEEE 754. As explained in #1083, this is intentional and the goal is to make == and < act consistently so that NaN can be used as a key in ordered collections, for example.

One downside of this is that programmers cannot apply knowledge or techniques learned from languages like Java or JavaScript that use IEEE 754 floating-point arithmetic.

Another problem is that differences between Rust and IEEE 754 are not specified, and do not appear to be implemented consistently. This makes it hard to know what to expect from Rust. Issue #1083 lists more problems with the current Rust semantics of NaN, but it is not clear which are intentional and which are not.

If this issue is closed as WONTFIX, then we should instead open a new issue to document Rust's floating point semantics.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions