This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[PATCH] Fix exp10 and coshl


Hi!

IMHO sysdeps/generic/ should have no knowledge about IEEE
single/double/extended double/quad formats.
Routines which need constant which depend on the exact number format should
be only in ieee754/*/ or in architecture dependent directories.
Using magic constants in coshl below e.g. caused coshl to issue an error
even for arguments which should be handled (the constant computed in generic
w_coshl was log(DBL_MAX)+M_LN2, not logl(LDBL_MAX)+M_LN2l) and errors with
ldbl-128 in both coshl and exp10l.
Either we should move these wrappers into appropriate sysdeps/ieee754/
directories and compute correct constants, or we can check
overflows/underflows without any cooked up constants which is what the patch
below does (then we can have just a single wrapper for each of these
functions).

2001-06-04  Jakub Jelinek  <jakub@redhat.com>

	* sysdeps/generic/w_coshl.c (__coshl): Test if finite argument
	gave non-finite result instead of using constant in generic
	version.
	* sysdeps/generic/w_coshf.c (__coshf): Likewise.
	* sysdeps/generic/w_cosh.c (__cosh): Likewise.
	* sysdeps/generic/w_exp10.c (o_threshold, u_threshold): Remove.
	(__exp10): Test if finite argument gave non-finite result.
	* sysdeps/generic/w_exp10f.c (o_threshold, u_threshold, __exp10f):
	Likewise.
	* sysdeps/generic/w_exp10l.c (o_threshold, u_threshold, __exp10l):
	Likewise.

--- libc/sysdeps/generic/w_coshl.c.jj	Sat Feb 17 02:41:50 2001
+++ libc/sysdeps/generic/w_coshl.c	Mon Jun  4 13:52:06 2001
@@ -38,7 +38,7 @@ static char rcsid[] = "$NetBSD: $";
 	long double z;
 	z = __ieee754_coshl(x);
 	if(_LIB_VERSION == _IEEE_ || __isnanl(x)) return z;
-	if(fabsl(x)>7.10475860073943863426e+02) {
+	if(!__finite(z) && __finite(x)) {
 	        return __kernel_standard(x,x,205); /* cosh overflow */
 	} else
 	    return z;
--- libc/sysdeps/generic/w_coshf.c.jj	Sat Feb 17 02:41:46 2001
+++ libc/sysdeps/generic/w_coshf.c	Mon Jun  4 13:52:32 2001
@@ -37,7 +37,7 @@ static char rcsid[] = "$NetBSD: w_coshf.
 	float z;
 	z = __ieee754_coshf(x);
 	if(_LIB_VERSION == _IEEE_ || __isnanf(x)) return z;
-	if(fabsf(x)>(float)8.9415985107e+01) {	
+	if(!__finite(z) && __finite(x)) {	
 		/* cosh overflow */
 	        return (float)__kernel_standard((double)x,(double)x,105);
 	} else
--- libc/sysdeps/generic/w_cosh.c.jj	Sat Feb 17 02:41:41 2001
+++ libc/sysdeps/generic/w_cosh.c	Mon Jun  4 13:52:55 2001
@@ -34,7 +34,7 @@ static char rcsid[] = "$NetBSD: w_cosh.c
 	double z;
 	z = __ieee754_cosh(x);
 	if(_LIB_VERSION == _IEEE_ || __isnan(x)) return z;
-	if(fabs(x)>7.10475860073943863426e+02) {
+	if(!__finite(z) && __finite(x)) {
 	        return __kernel_standard(x,x,5); /* cosh overflow */
 	} else
 	    return z;
--- libc/sysdeps/generic/w_exp10.c.jj	Sat Feb 17 02:42:06 2001
+++ libc/sysdeps/generic/w_exp10.c	Mon Jun  4 13:57:14 2001
@@ -21,14 +21,6 @@
 #include "math_private.h"
 
 #ifdef __STDC__
-static const double
-#else
-static double
-#endif
-o_threshold=  3.0825471555991674389672e+02,
-u_threshold= -3.2360724533877978485251e+02;
-
-#ifdef __STDC__
 	double __exp10(double x)		/* wrapper exp10 */
 #else
 	double __exp10(x)			/* wrapper exp10 */
@@ -41,11 +33,9 @@ u_threshold= -3.2360724533877978485251e+
 	double z;
 	z = __ieee754_exp10(x);
 	if(_LIB_VERSION == _IEEE_) return z;
-	if(__finite(x)) {
-	    if(x>o_threshold)
-	        return __kernel_standard(x,x,46); /* exp10 overflow */
-	    else if(x<u_threshold)
-	        return __kernel_standard(x,x,47); /* exp10 underflow */
+	if(!__finite(z) && __finite(x)) {
+	    /* exp10 overflow (46) if x > 0, underflow (47) if x < 0.  */
+	    return __kernel_standard(x,x,46+!!__signbit(x));
 	}
 	return z;
 #endif
--- libc/sysdeps/generic/w_exp10f.c.jj	Sat Feb 17 02:42:10 2001
+++ libc/sysdeps/generic/w_exp10f.c	Mon Jun  4 13:59:10 2001
@@ -21,14 +21,6 @@
 #include "math_private.h"
 
 #ifdef __STDC__
-static const float
-#else
-static float
-#endif
-o_threshold=  3.853183944498959298709e+01,
-u_threshold= -4.515449934959717928174e+01;
-
-#ifdef __STDC__
 	float __exp10f(float x)		/* wrapper exp10f */
 #else
 	float __exp10f(x)			/* wrapper exp10f */
@@ -41,13 +33,10 @@ u_threshold= -4.515449934959717928174e+0
 	float z;
 	z = __ieee754_exp10f(x);
 	if(_LIB_VERSION == _IEEE_) return z;
-	if(__finitef(x)) {
-	    if(x>o_threshold)
-	        /* exp overflow */
-	        return (float)__kernel_standard((double)x,(double)x,146);
-	    else if(x<u_threshold)
-	        /* exp underflow */
-	        return (float)__kernel_standard((double)x,(double)x,147);
+	if(!__finitef(z) && __finitef(x)) {
+	    /* exp10f overflow (146) if x > 0, underflow (147) if x < 0.  */
+	    return (float)__kernel_standard((double) x, (double) x,
+					    146+!!__signbitf(x));
 	}
 	return z;
 #endif
--- libc/sysdeps/generic/w_exp10l.c.jj	Sat Feb 17 02:42:14 2001
+++ libc/sysdeps/generic/w_exp10l.c	Mon Jun  4 14:00:17 2001
@@ -22,14 +22,6 @@
 #include "math_private.h"
 
 #ifdef __STDC__
-static const long double
-#else
-static long double
-#endif
-o_threshold=  4.93207544895866790234755e+03,
-u_threshold= -4.95104033868549871764588e+03;
-
-#ifdef __STDC__
 	long double __exp10l(long double x)	/* wrapper exp10 */
 #else
 	long double __exp10l(x)			/* wrapper exp10 */
@@ -42,11 +34,9 @@ u_threshold= -4.95104033868549871764588e
 	long double z;
 	z = __ieee754_exp10l(x);
 	if(_LIB_VERSION == _IEEE_) return z;
-	if(__finitel(x)) {
-	    if(x>o_threshold)
-	        return __kernel_standard(x,x,246); /* exp10 overflow */
-	    else if(x<u_threshold)
-	        return __kernel_standard(x,x,247); /* exp10 underflow */
+	if(!__finitel(z) && __finitel(x)) {
+	    /* exp10 overflow (246) if x > 0, underflow (247) if x < 0.  */
+	    return __kernel_standard(x,x,246+__signbitl(x));
 	}
 	return z;
 #endif

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]