Skip to content

f32 formatter produces strange results #63171

Open
@emilio

Description

@emilio

Test-case:

fn main() {
    let f = 2147483648.0f32;
    println!("{} | {}", f, f as f64)
}

I expected both to produce the same number, since that number is a perfectly representable f32 value.

This bit me because I was investigating an issue where values close to integer limits were treated as negative.

Seeing 2147483600 (in range for an i32) rather than the actual value 2147483648 (out of range for an i32) made it all really confusing.

Anyhow, I'll fix Firefox to do the proper bounds check, but it would've been nice to avoid the extra confusion time :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-floating-pointArea: Floating point numbers and arithmeticA-fmtArea: `core::fmt`C-bugCategory: This is a bug.T-libs-apiRelevant to the library API 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