Bug #11175
libm should use signbit() correctly
Start date:
Due date:
% Done:
100%
Estimated time:
Difficulty:
Medium
Tags:
Gerrit CR:
Description
After 10881, the tanh()
function in libm.so.2
is no longer returning the correct sign for a negative argument.
Small reproducer:
#include <stdio.h> #include <math.h> int main() { double a; a = -1; printf("tanh(%f) = %f\n", a, tanh(a)); a = 1; printf("tanh(%f) = %f\n", a, tanh(a)); return 0; }
bloody% gcc -m32 -o tanh-32 tanh.c -lm bloody% gcc -m64 -o tanh-64 tanh.c -lm bloody% ./tanh-32 tanh(-1.000000) = 0.761594 tanh(1.000000) = 0.761594 bloody% ./tanh-64 tanh(-1.000000) = -0.761594 tanh(1.000000) = 0.761594
This seems to be related to the change to use __builtin_signbit()
- if I remove that definition from math_c99.h
and rebuild libm, then tanh()
produces the correct results.
Related issues
Updated by Andy Fiddaman almost 2 years ago
- Related to Bug #10881: more C99 math macros should be compiler builtins added
Updated by Till Wegmüller almost 2 years ago
On current (patchlevel today) OpenIndiana I get
vagrant@openindiana:~$ gcc -m32 -o tanh-32 tanh.c -lm vagrant@openindiana:~$ gcc -m64 -o tanh-64 tanh.c -lm vagrant@openindiana:~$ ./tanh-32 tanh(-1.000000) = -0.761594 tanh(1.000000) = 0.761594 vagrant@openindiana:~$ ./tanh-64 tanh(-1.000000) = -0.761594 tanh(1.000000) = 0.761594
Updated by Rich Lowe almost 2 years ago
This is because signbit() is defined to return <i>non-0</i> for negative numbers, wheres tanh(3M) is explicitly comparing it to 1.
jn(3M) is also broken.
Updated by Rich Lowe over 1 year ago
- Subject changed from tanh() sign broken for 32-bit after 10881 to libm should use signbit() correctly
- Category set to lib - userland libraries
- Assignee set to Rich Lowe
Updated by Electric Monk over 1 year ago
- Status changed from New to Closed
- % Done changed from 0 to 100
git commit 685c1a21304711e8d0a21bade51b783487d53044
commit 685c1a21304711e8d0a21bade51b783487d53044 Author: Richard Lowe <richlowe@richlowe.net> Date: 2019-06-06T20:20:31.000Z 11175 libm should use signbit() correctly 11188 c99 math macros should return strictly backward compatible values Reviewed by: Andy Fiddaman <andy@omniosce.org> Reviewed by: Igor Kozhukhov <igor@dilos.org> Approved by: Dan McDonald <danmcd@joyent.com>