* asinh() gives NaN on Linux/x86/glibc with optimization on
@ 1998-12-22 15:20 Shimpei Yamashita
1998-12-22 15:48 ` H.J. Lu
0 siblings, 1 reply; 8+ messages in thread
From: Shimpei Yamashita @ 1998-12-22 15:20 UTC (permalink / raw)
To: mlist-egcs
On RedHat Linux 5.2 (using glibc 2.0.7) for x86, asinh() returns NaN
for negative arguments if optimizations are on. The error does not
occur if optimizations are turned off. I'm not sure where the problem
is--egcs or glibc. Using libc5 seems to solve the problem, but so does
dropping back to gcc 2.7.2.
--
Shimpei Yamashita < http://www.submm.caltech.edu/%7Eshimpei/ >
^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <egcs.m0zsbWu-00038vC@ocean.lucon.org>]
* Re: asinh() gives NaN on Linux/x86/glibc with optimization on
[not found] <egcs.m0zsbWu-00038vC@ocean.lucon.org>
@ 1998-12-22 15:59 ` Shimpei Yamashita
1998-12-22 16:05 ` H.J. Lu
1998-12-22 19:52 ` Horst von Brand
0 siblings, 2 replies; 8+ messages in thread
From: Shimpei Yamashita @ 1998-12-22 15:59 UTC (permalink / raw)
To: mlist-egcs
H.J. Lu <hjl@lucon.org> writes:
>
>>
>> On RedHat Linux 5.2 (using glibc 2.0.7) for x86, asinh() returns NaN
>> for negative arguments if optimizations are on. The error does not
>> occur if optimizations are turned off. I'm not sure where the problem
>> is--egcs or glibc. Using libc5 seems to solve the problem, but so does
>> dropping back to gcc 2.7.2.
>
>Do you have a testcase?
Sure.
#include <stdio.h>
#include <math.h>
main() {
double ha;
printf("Input argument for asinh: ");
scanf("%lf", &ha);
printf("asinh(%f)=%f\n", ha, asinh(ha));
exit(0);
}
The program works correctly for positive arguments. Negative results
(I tried -100, -50, -10, -5) all return NaN.
--
Shimpei Yamashita < http://www.submm.caltech.edu/%7Eshimpei/ >
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: asinh() gives NaN on Linux/x86/glibc with optimization on
1998-12-22 15:59 ` Shimpei Yamashita
@ 1998-12-22 16:05 ` H.J. Lu
1998-12-22 19:52 ` Horst von Brand
1 sibling, 0 replies; 8+ messages in thread
From: H.J. Lu @ 1998-12-22 16:05 UTC (permalink / raw)
To: Shimpei Yamashita; +Cc: egcs
>
> H.J. Lu <hjl@lucon.org> writes:
> >
> >>
> >> On RedHat Linux 5.2 (using glibc 2.0.7) for x86, asinh() returns NaN
> >> for negative arguments if optimizations are on. The error does not
> >> occur if optimizations are turned off. I'm not sure where the problem
> >> is--egcs or glibc. Using libc5 seems to solve the problem, but so does
> >> dropping back to gcc 2.7.2.
> >
> >Do you have a testcase?
>
> Sure.
>
> #include <stdio.h>
> #include <math.h>
>
> main() {
>
> double ha;
>
> printf("Input argument for asinh: ");
> scanf("%lf", &ha);
> printf("asinh(%f)=%f\n", ha, asinh(ha));
> exit(0);
> }
>
> The program works correctly for positive arguments. Negative results
> (I tried -100, -50, -10, -5) all return NaN.
>
# gcc -v
Reading specs from /usr/lib/gcc-lib/i586-pc-linux/egcs-2.91.60/specs
gcc version egcs-2.91.60 19981201 (egcs-1.1.1 release)
# gcc -O6 x.c
# a.out
Input argument for asinh: -100
asinh(-100.000000)=-5.298342
# ldd a.out
libc.so.6 => /lib/libc.so.6 (0x40007000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x2aaaa000)
# ls -l /lib/libc.so.6
lrwxrwxrwx 1 root root 26 Dec 11 08:16 /lib/libc.so.6 -> glibc-2.0-981211/libc.so.6
I am running glibc 2.0.7 981211.
--
H.J. Lu (hjl@gnu.org)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: asinh() gives NaN on Linux/x86/glibc with optimization on
1998-12-22 15:59 ` Shimpei Yamashita
1998-12-22 16:05 ` H.J. Lu
@ 1998-12-22 19:52 ` Horst von Brand
1 sibling, 0 replies; 8+ messages in thread
From: Horst von Brand @ 1998-12-22 19:52 UTC (permalink / raw)
To: Shimpei Yamashita; +Cc: mlist-egcs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 742 bytes --]
Shimpei Yamashita <shimpei+usenet+.mil+.gov@BOFH.submm.caltech.edu> said:
> H.J. Lu <hjl@lucon.org> writes:
> >> On RedHat Linux 5.2 (using glibc 2.0.7) for x86, asinh() returns NaN
> >> for negative arguments if optimizations are on. The error does not
> >> occur if optimizations are turned off. I'm not sure where the problem
> >> is--egcs or glibc. Using libc5 seems to solve the problem, but so does
> >> dropping back to gcc 2.7.2.
The case given works reasonably with egcs-19981213, glibc-2.0.108 with -O2
-fomit-frame-pointer and without optimization (non-inlined asinh()).
--
Horst von Brand vonbrand@sleipnir.valparaiso.cl
Casilla 9G, Viña del Mar, Chile +56 32 672616
^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <egcs.m0zsbnn-00038vC@ocean.lucon.org>]
* Re: asinh() gives NaN on Linux/x86/glibc with optimization on
[not found] <egcs.m0zsbnn-00038vC@ocean.lucon.org>
@ 1998-12-22 17:29 ` Shimpei Yamashita
1998-12-22 19:51 ` Jeffrey A Law
0 siblings, 1 reply; 8+ messages in thread
From: Shimpei Yamashita @ 1998-12-22 17:29 UTC (permalink / raw)
To: mlist-egcs
H.J. Lu <hjl@lucon.org> writes:
[me saying asinh of negative number gives wrong answer]
>
># gcc -v
>Reading specs from /usr/lib/gcc-lib/i586-pc-linux/egcs-2.91.60/specs
>gcc version egcs-2.91.60 19981201 (egcs-1.1.1 release)
># gcc -O6 x.c
># a.out
>Input argument for asinh: -100
>asinh(-100.000000)=-5.298342
># ldd a.out
> libc.so.6 => /lib/libc.so.6 (0x40007000)
> /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x2aaaa000)
># ls -l /lib/libc.so.6
>lrwxrwxrwx 1 root root 26 Dec 11 08:16 /lib/libc.so.6 ->
>glibc-2.0-981211/libc.so.6
>
>I am running glibc 2.0.7 981211.
Hmm. That's funny. That's exactly what I did and I get NaN's for
answer. I'm using the version of glibc that came with RedHat 5.2, so
maybe that's the problem. OTOH, what kind of a bug in the library
would cause different optimizations in the *calling* program to give
different results?
BTW, where do I get the new snapshots of glibc? The snapshot
repository in ftp.kernel.org doesn't seem to be updated anymore.
--
Shimpei Yamashita < http://www.submm.caltech.edu/%7Eshimpei/ >
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: asinh() gives NaN on Linux/x86/glibc with optimization on
1998-12-22 17:29 ` Shimpei Yamashita
@ 1998-12-22 19:51 ` Jeffrey A Law
1998-12-22 22:34 ` H.J. Lu
0 siblings, 1 reply; 8+ messages in thread
From: Jeffrey A Law @ 1998-12-22 19:51 UTC (permalink / raw)
To: Shimpei Yamashita; +Cc: mlist-egcs
In message < 75ph1i$phv@gap.cco.caltech.edu >you write:
> H.J. Lu <hjl@lucon.org> writes:
> [me saying asinh of negative number gives wrong answer]
> >
> ># gcc -v
> >Reading specs from /usr/lib/gcc-lib/i586-pc-linux/egcs-2.91.60/specs
> >gcc version egcs-2.91.60 19981201 (egcs-1.1.1 release)
> ># gcc -O6 x.c
> ># a.out
> >Input argument for asinh: -100
> >asinh(-100.000000)=-5.298342
> ># ldd a.out
> > libc.so.6 => /lib/libc.so.6 (0x40007000)
> > /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x2aaaa000)
> ># ls -l /lib/libc.so.6
> >lrwxrwxrwx 1 root root 26 Dec 11 08:16 /lib/libc.so.6 ->
> >glibc-2.0-981211/libc.so.6
> >
> >I am running glibc 2.0.7 981211.
>
> Hmm. That's funny. That's exactly what I did and I get NaN's for
> answer. I'm using the version of glibc that came with RedHat 5.2, so
> maybe that's the problem. OTOH, what kind of a bug in the library
> would cause different optimizations in the *calling* program to give
> different results?
>
> BTW, where do I get the new snapshots of glibc? The snapshot
> repository in ftp.kernel.org doesn't seem to be updated anymore.
I presume you're running glibc-2.0.7?
Here's an analysis of an earlier problem with asinh with glibc-2.0.7:
I think I've figured it out, but looking at the x86 assembly code
actually wasn't that much help, since the code is correct. The
problem is glibc 2.0.7's inline definition of asinh() in
/usr/include/__math.h. This definition has a misplaced paren which
breaks it for negative arguments. The inline definition is not
included when compiling under gcc 2.7.x, but is included when running
newer versions of gcc or egcs. Since the inline definition is only
used when optimization is turned on, and since the actual library
definition of asinh() in glibc is apparently correct, the bug only
shows up when optimizing.
Here's glibc 2.0.7's definition of asinh() from /usr/include/__math.h:
__MATH_INLINE double asinh (double __x);
__MATH_INLINE double
asinh (double __x)
{
register double __y = fabs (__x);
return log1p ((__y * __y / (sqrt (__y * __y + 1.0) + 1.0) + __y)
* __sgn1 (__x));
}
Here's a correct definition:
__MATH_INLINE double asinh (double __x);
__MATH_INLINE double
asinh (double __x)
{
register double __y = fabs (__x);
return log1p ((__y * __y / (sqrt (__y * __y + 1.0) + 1.0) + __y))
* __sgn1 (__x);
}
The __sgn1() function (which computes the sign of its argument) should
go outside the log1p(), not inside it. The argument of log1p() is
supposed to be positive here. The __sgn1() is meant to invert the
sign of the result for negative arguments of asinh(), since asinh(-x)
= -asinh(x).
(Actually this correction gives an extra pair of parens around the
argument of log1p(), which could be removed.)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: asinh() gives NaN on Linux/x86/glibc with optimization on
1998-12-22 19:51 ` Jeffrey A Law
@ 1998-12-22 22:34 ` H.J. Lu
0 siblings, 0 replies; 8+ messages in thread
From: H.J. Lu @ 1998-12-22 22:34 UTC (permalink / raw)
To: law; +Cc: shimpei+usenet+.mil+.gov, mlist-egcs
> Here's glibc 2.0.7's definition of asinh() from /usr/include/__math.h:
>
> __MATH_INLINE double asinh (double __x);
> __MATH_INLINE double
> asinh (double __x)
> {
> register double __y = fabs (__x);
>
> return log1p ((__y * __y / (sqrt (__y * __y + 1.0) + 1.0) + __y)
> * __sgn1 (__x));
> }
>
> Here's a correct definition:
>
> __MATH_INLINE double asinh (double __x);
> __MATH_INLINE double
> asinh (double __x)
> {
> register double __y = fabs (__x);
>
> return log1p ((__y * __y / (sqrt (__y * __y + 1.0) + 1.0) + __y))
> * __sgn1 (__x);
> }
>
> The __sgn1() function (which computes the sign of its argument) should
> go outside the log1p(), not inside it. The argument of log1p() is
> supposed to be positive here. The __sgn1() is meant to invert the
> sign of the result for negative arguments of asinh(), since asinh(-x)
> = -asinh(x).
>
> (Actually this correction gives an extra pair of parens around the
> argument of log1p(), which could be removed.)
>
1998-10-26 Ulrich Drepper <drepper@cygnus.com>
* sysdeps/i386/fpu/__math.h (asinh): Put __sgn1 call outside log1p
call.
--
H.J. Lu (hjl@gnu.org)
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~1998-12-22 22:34 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-12-22 15:20 asinh() gives NaN on Linux/x86/glibc with optimization on Shimpei Yamashita
1998-12-22 15:48 ` H.J. Lu
[not found] <egcs.m0zsbWu-00038vC@ocean.lucon.org>
1998-12-22 15:59 ` Shimpei Yamashita
1998-12-22 16:05 ` H.J. Lu
1998-12-22 19:52 ` Horst von Brand
[not found] <egcs.m0zsbnn-00038vC@ocean.lucon.org>
1998-12-22 17:29 ` Shimpei Yamashita
1998-12-22 19:51 ` Jeffrey A Law
1998-12-22 22:34 ` H.J. Lu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).