Skip to content

<{f16,f32,f64,f128} as Rem>::rem documented definition is misleading w.r.t. intermediate rounding #133758

Open
@traviscross

Description

@traviscross

Our documentation for impl Rem for {f16, f32, f64, f128} says:

The remainder has the same sign as the dividend and is computed as: x - (x / y).trunc() * y.

But that's not true. E.g.:

fn main() {
    let (x, y) = (11f64, 1.1f64);
    assert_eq!(x - (x / y).trunc() * y, x % y);
    //~^ PANIC
    // assertion `left == right` failed
    // left: 0.0
    // right: 1.0999999999999992
}

This mismatch creates a hazard when trying to correctly encode algorithms that rely on this semantic.

This tripped me up, e.g., when authoring:

cc #133485 #107904

cc @cuviper @Noratrieb @tczajka @Neutron3529 @BartMassey

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-bugCategory: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions