NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/58742: Sign of Zero Issue with libc fma(): Positive Zero Returned Instead of Negative



>Number:         58742
>Category:       lib
>Synopsis:       Sign of Zero Issue with libc fma(): Positive Zero Returned Instead of Negative
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Oct 11 20:25:00 +0000 2024
>Originator:     Furkan Onder
>Release:        NetBSD 10.0
>Organization:
>Environment:
NetBSD home.localhost 10.0 NetBSD 10.0 (GENERIC) #0: Thu Mar 28 08:33:33 UTC 2024  mkrepro%mkrepro.NetBSD.org@localhost:/usr/src/sys/arch/amd64/compile/GENERIC amd64
>Description:
There is an inconsistency in the behavior of the fma() function in the libc implementation, where it returns positive zero instead of the expected negative zero in certain floating-point arithmetic scenarios. The problem is that the Python test suite fails on NetBSD x86_64 on tests on the test_fma_zero_result().

https://github.com/python/cpython/blob/92760bd85b8f48b88df5b81100a757048979de83/Lib/test/test_math.py#L2724-L2776

>How-To-Repeat:
Example to Reproduce:
```
#include <math.h>
#include <stdio.h>

int main() {
  volatile double x = 0x1p-500, y = 0x1p-550, z = 0x1p-1000;
  double a, b, c, r;

  a = x - y;
  b = x + y;
  c = -z;
  r = fma(a, b, c);

  printf("fma(%+a, %+a, %+a) = %+g\n", a, b, c, r);
  return 0;
}
```

On Linux x86_64:
```
$ gcc fma-test.c -lm -o fma-test
$ ./fma-test
fma(+0x1.ffffffffffff8p-501, +0x1.0000000000004p-500, -0x1p-1000) = -0
```


On NetBSD x86_64:
```
$ gcc fma-test.c -lm -o fma-test
$ ./fma-test
fma(+0x1.ffffffffffff8p-501, +0x1.0000000000004p-500, -0x1p-1000) = +0
$
```

Program should print -0 instead of +0.
>Fix:



Home | Main Index | Thread Index | Old Index