Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Incorrect fmaf results on some inputs #263

@afonso360

Description

@afonso360

Hey,

As part of investigating a unrelated issue I found an input for fmaf where libm returns a different result from the native fmadd instruction on aarch64. Note, the issue is arch independent, I'm using aarch64 to compare because it has a native fmadd instruction.

The result is only off by 1 ULP, does libm target this level of precision?

Here's the example program:

fn main() {
    let a = f32::from_bits(1266679807);
    let b = f32::from_bits(1300234242);
    let c = f32::from_bits(1115553792);
    let expected = f32::from_bits(1501560833);


    let native_mul_add = a.mul_add(b, c);
    let native_bits = native_mul_add.to_bits();

    let libm = libm::fmaf(a, b, c);
    let libm_bits = libm.to_bits();

    println!("expected: {}", expected.to_bits());
    println!("native  : {}", native_bits);
    println!("libm    : {}", libm_bits);
}

Outputs:

expected: 1501560833
native  : 1501560833
libm    : 1501560834

I don't think this is related to #200, I don't get a panic.


Another input that also fails is:

a = 1484783617
b = 1488977920
c = 2147483649

// Results:
native = 1908408321
libm   = 1908408322

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