Skip to content

Casting the same i64 and u64 integers to f32 gives different results on i686-pc-windows-msvc target #105626

Closed
@ghost

Description

I tried this code:

fn main() {
    let mut n: i64 = 0b0000000000111111111111111111111111011111111111111111111111111111;
    println!("{}, {}, {}, {}", n, n as i64 as f32, n as u64 as f32, n as u128 as f32);
    assert_ne!((n as f64) as f32, n as f32);
    assert_eq!(n as i64 as f32, n as u64 as f32);
    n = -n;
    assert_ne!((n as f64) as f32, n as f32);
    assert_eq!(n as i64 as f32, -(-n as u64 as f32));
}

rust-num/num-bigint#261

I expected to see this happen:

The code prints the output below and exits successfully.

18014397972611071, 18014397000000000, 18014397000000000, 18014397000000000

Instead, this happened:

The code prints the output below and panics.

18014397972611071, 18014397000000000, 18014399000000000, 18014397000000000

Meta

rustc --version --verbose:

rustc 1.65.0 (897e37553 2022-11-02)
binary: rustc
commit-hash: 897e37553bba8b42751c67658967889d11ecd120
commit-date: 2022-11-02
host: x86_64-pc-windows-msvc
release: 1.65.0
LLVM version: 15.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-floating-pointArea: Floating point numbers and arithmeticC-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions