Skip to content

MIR is double-rounding f32 literals #32805

Closed
@arielb1

Description

@arielb1

STR

#![feature(rustc_attrs)]

#[rustc_mir]
fn const_mir() -> f32 { 9007199791611905.0 }

fn const_old() -> f32 { 9007199791611905.0 }

fn main() {
    let s = "9007199791611905.0"; // (1<<53)+(1<<29)+1
    println!("old: {}", const_old());
    println!("MIR: {}", const_mir());
    println!("single rounding: {}", s.parse::<f32>().unwrap());
    println!("double rounding: {}", s.parse::<f64>().unwrap() as f32);
}

Expected Result

Both MIR and old trans should use a single rounding, that's it

old: 9007200000000000
MIR: 9007200000000000
single rounding: 9007200000000000
double rounding: 9007199000000000

Actual Result

old trans is single-rounding as it should, but MIR is doing a double rounding:

old: 9007200000000000
MIR: 9007199000000000
single rounding: 9007200000000000
double rounding: 9007199000000000

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions