Project

General

Profile

Bug #11175

libm should use signbit() correctly

Added by Andy Fiddaman 5 months ago. Updated 4 months ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
lib - userland libraries
Start date:
Due date:
% Done:

100%

Estimated time:
Difficulty:
Medium
Tags:

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

Related to illumos gate - Bug #10881: more C99 math macros should be compiler builtinsClosed2019-04-28

Actions

History

#1

Updated by Andy Fiddaman 5 months ago

  • Related to Bug #10881: more C99 math macros should be compiler builtins added
#2

Updated by Till Wegmüller 5 months 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
#3

Updated by Rich Lowe 5 months 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.

#4

Updated by Rich Lowe 5 months 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
#5

Updated by Electric Monk 4 months 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>

Also available in: Atom PDF