Skip to content

Subnormal f64 to f32 cast is incorrect in CTFE #113407

Closed
rust-lang/rustc_apfloat
#1
@cbeuw

Description

@cbeuw
pub fn main() {
    let f = f64::from_bits(0x19873cc2) as f32;
    println!("{:x}", f.to_bits());
    println!("{}", f == 0.);
}
$ rustc -Zmir-opt-level=2 -Copt-level=3 repro.rs && ./repro
1
false
$ ../miri/miri run repro.rs 2> /dev/null
1
false
$ rustc -Zmir-opt-level=1 -Copt-level=3 repro.rs && ./repro
0
true

It should print 0 and true, according to the equivalent C program: https://godbolt.org/z/7Gq51a1Yh

This is probably another apfloat bug

$ rustc --version -v 
rustc 1.72.0-nightly (d9c13cd45 2023-07-05)
binary: rustc
commit-hash: d9c13cd4531649c2028a8384cb4d4e54f985380e
commit-date: 2023-07-05
host: aarch64-unknown-linux-gnu
release: 1.72.0-nightly
LLVM version: 16.0.5

(reproducible on x86 as well)

cc @eddyb @wesleywiser @RalfJung

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-propArea: Constant propagationA-floating-pointArea: Floating point numbers and arithmeticA-mir-optArea: MIR optimizationsI-slowIssue: Problems and improvements with respect to performance of generated code.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions