Skip to content

Usage of "non-deterministic" floating point operations is misleading #150323

@JLErvin

Description

@JLErvin

Location (URL)

https://doc.rust-lang.org/std/primitive.f32.html#unspecified-precision-1

Summary

There are a number of floating point operations which are documented with the following language (e.g. f32::exp):

The precision of this function is non-deterministic. This means it varies by platform, Rust version, and can even differ within the same execution from one invocation to the next.

The language of "non-determinism" was introduced in this pull request: #124609. I would argue, however, that the usage of "non-determinism", paired with the language "... can even differ within the same execution from one invocation to the next" does not fully reflect the nuance that this comment is trying to document.

Backtracking through some PRs and issues, it seems that the root cause of this work is from #109118 and #71355. These highlight that the same core floating point operation can produce different results depending on the platform, release/debug mode, and whether or not the operation is performed at runtime or compilation time.

However, there is an important nuance, which I expect to be true, that the same compiled binary shall always produce the same outputs bits when given identical inputs bits for the same floating point operation. If this claim is not true, I would be extremely interested in examples where this is the case.

My understanding is that this claim is true, however, in which case I think the documentation should be updated to reflect it. I'm no wordsmith myself, but something like: "The precision of this function can vary depending on the platform, Rust version, compilation mode, and whether or not the value is generated at compile-time or runtime. For a given binary running on identical hardware, however, bit-for-bit identical inputs shall always produce identical bit-for-bit outputs."

For some context, a project I am working on runs a number of single-threaded, redundant computing operations on distributed, identical hardware, and then exchanges information to come to a consensus on the output. I am not aware of any instances where identical inputs to the internal floating-point calculations would produce different outputs. The documentation seems to suggest that it could.

I'm happy to open any PRs to make these changes, but I'd like some feedback first on the nuances before doing so.

cc @RalfJung who wrote the current documentation

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsA-floating-pointArea: Floating point numbers and arithmeticneeds-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions