Skip to content

Rounding error in __mulsf3 #616

Closed
@tgross35

Description

@tgross35

This is a problem in Rust's compiler-builtins, but also the LLVM library (which is demonstrated here). The correct answer should be 0.0.

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=54ee2169049eb22eb1b44d41c6f37e1e

extern "C" {
    fn __mulsf3(a: f32, b: f32) -> f32;
}

fn main() {
    let a = 7.83651e-39f32;
    let b = 2.7310085e-8f32;
    let res_asm = a * b ;
    let res_mulsf3 = unsafe { __mulsf3(a, b) };
    println!("asm {} {:#010x}", res_asm, res_asm.to_bits());
    println!("mulsf3 {} {:#010x}", res_mulsf3, res_mulsf3.to_bits());
}
asm 0 0x00000000
mulsf3 0.000000000000000000000000000000000000000000001 0x00000001

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