Skip to content

largs floats print slightly wrong #18038

Closed
@ben0x539

Description

@ben0x539

Lowest roundtripping-integral positive examples I found:

extern {
    fn printf(fmt: *const u8, ...);
}

fn main() {
    let f1: f32 = 41943048_u32 as f32;
    let f2: f64 = 22517998136852488_u64 as f64;
    println!("rust: {}, {}", f1, f2);
    unsafe { printf("c:    %.0f, %.0f\n\0".as_ptr(), f1 as f64, f2); }
}

prints

rust: 41943058, 22517998136852498
c:    41943048, 22517998136852488

We're well past where integers can be roundtripped through floats precisely, but these two examples in particular do roundtrip, so it's weird that we're off by ten when printing them, and anyway C gets it right.

cc #6220?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions