Skip to content

u64 to f32 conversion is inaccurate on Windows 32bit #59787

Closed
@ghost

Description

On Windows, the x87 control word has a different default value than on other platforms. This not only introduces floating point precision issues, but also results in inconsistent behavior with other platforms. I tried to avoid using x87 by adding the -msse2 option when compiling for Windows 32bit, but the compiler still generates binaries using only x87.

The code below outputs differently on Windows 32bit than on other platforms:

#include <stdio.h>
#include <stdint.h>

int main() {
    int64_t n = 0b0000000000111111111111111111111111011111111111111111111111111111;
    printf("%lld, %.0f, %.0f", n, (float)n, (float)(uint64_t)n);

    return 0;
}

rust-lang/rust#105626

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions