summaryrefslogtreecommitdiffstats
path: root/lib/libm/noieee_src
diff options
context:
space:
mode:
authormartynas <martynas@openbsd.org>2008-06-25 17:49:31 +0000
committermartynas <martynas@openbsd.org>2008-06-25 17:49:31 +0000
commit9ba807bf0dd12b9a63c88f0e58513dc2845e9579 (patch)
treeaa6de94eaa3f7cadfbc4cc9a551b15bc76833e32 /lib/libm/noieee_src
parent`Li' needs an argument; (diff)
downloadwireguard-openbsd-9ba807bf0dd12b9a63c88f0e58513dc2845e9579.tar.xz
wireguard-openbsd-9ba807bf0dd12b9a63c88f0e58513dc2845e9579.zip
- expressions such as x != x and x == x are prone to errors and
ugly, when we have isnan and isinf - no need to check for _IEEE, when checking for not-a-number - remove some impossible checks - while here, drem->remainder, as drem is just an obsolete alias now ok millert@
Diffstat (limited to 'lib/libm/noieee_src')
-rw-r--r--lib/libm/noieee_src/n_cabs.c24
-rw-r--r--lib/libm/noieee_src/n_floor.c4
-rw-r--r--lib/libm/noieee_src/n_j1.c7
-rw-r--r--lib/libm/noieee_src/n_jn.c4
-rw-r--r--lib/libm/noieee_src/n_pow.c10
-rw-r--r--lib/libm/noieee_src/n_sincos.c6
-rw-r--r--lib/libm/noieee_src/n_support.c13
-rw-r--r--lib/libm/noieee_src/n_tan.c6
8 files changed, 37 insertions, 37 deletions
diff --git a/lib/libm/noieee_src/n_cabs.c b/lib/libm/noieee_src/n_cabs.c
index 14709b7e2e8..d1c913fd702 100644
--- a/lib/libm/noieee_src/n_cabs.c
+++ b/lib/libm/noieee_src/n_cabs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: n_cabs.c,v 1.8 2008/06/21 08:26:19 martynas Exp $ */
+/* $OpenBSD: n_cabs.c,v 1.9 2008/06/25 17:49:31 martynas Exp $ */
/* $NetBSD: n_cabs.c,v 1.1 1995/10/10 23:36:39 ragge Exp $ */
/*
* Copyright (c) 1985, 1993
@@ -141,18 +141,18 @@ hypot(double x, double y)
}
- else if(y==y) /* y is +-INF */
+ else if(isinf(y)) /* y is +-INF */
return(copysign(y,one));
else
- return(y); /* y is NaN and x is finite */
+ return(y); /* y is NaN and x is finite */
- else if(x==x) /* x is +-INF */
+ else if(isinf(x)) /* x is +-INF */
return (copysign(x,one));
else if(finite(y))
- return(x); /* x is NaN, y is finite */
+ return(x); /* x is NaN, y is finite */
else if (isnan(y))
return (y);
- else return(copysign(y,one)); /* y is INF */
+ else return(copysign(y,one)); /* y is INF */
}
/* CABS(Z)
@@ -211,16 +211,16 @@ hypot(double x, double y)
return(scalbn(sqrt(x*x+y*y),exp));
}
- else if(y==y) /* y is +-INF */
+ else if(isinf(y)) /* y is +-INF */
return(copysign(y,one));
else
- return(y); /* y is NaN and x is finite */
+ return(y); /* y is NaN and x is finite */
- else if(x==x) /* x is +-INF */
+ else if(isinf(x)) /* x is +-INF */
return (copysign(x,one));
else if(finite(y))
- return(x); /* x is NaN, y is finite */
- else if(y!=y) return(y); /* x and y is NaN */
- else return(copysign(y,one)); /* y is INF */
+ return(x); /* x is NaN, y is finite */
+ else if(isnan(y)) return(y); /* x and y is NaN */
+ else return(copysign(y,one)); /* y is INF */
}
#endif
diff --git a/lib/libm/noieee_src/n_floor.c b/lib/libm/noieee_src/n_floor.c
index 7eeda6ceaa0..3e45d05e159 100644
--- a/lib/libm/noieee_src/n_floor.c
+++ b/lib/libm/noieee_src/n_floor.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: n_floor.c,v 1.7 2008/06/21 08:26:19 martynas Exp $ */
+/* $OpenBSD: n_floor.c,v 1.8 2008/06/25 17:49:31 martynas Exp $ */
/* $NetBSD: n_floor.c,v 1.1 1995/10/10 23:36:48 ragge Exp $ */
/*
* Copyright (c) 1985, 1993
@@ -94,7 +94,7 @@ ceil(double x)
* = 2**52; for IEEE 754 Double
* real s,t;
* begin
- * if x != x then return x; ... NaN
+ * if isnan(x) then return x; ... NaN
* if |x| >= L then return x; ... already an integer
* s := copysign(L,x);
* t := x + s; ... = (x+s) rounded to integer
diff --git a/lib/libm/noieee_src/n_j1.c b/lib/libm/noieee_src/n_j1.c
index cd147f548ec..dae88b56afe 100644
--- a/lib/libm/noieee_src/n_j1.c
+++ b/lib/libm/noieee_src/n_j1.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: n_j1.c,v 1.5 2008/06/21 08:26:19 martynas Exp $ */
+/* $OpenBSD: n_j1.c,v 1.6 2008/06/25 17:49:31 martynas Exp $ */
/* $NetBSD: n_j1.c,v 1.1 1995/10/10 23:36:53 ragge Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -148,7 +148,7 @@ j1(double x)
double z, s,c,ss,cc,r,u,v,y;
y = fabs(x);
if (!finite(x)) /* Inf or NaN */
- if (_IEEE && x != x)
+ if (isnan(x))
return(x);
else
return (copysign(x, zero));
@@ -211,8 +211,7 @@ y1(double x)
double z, s, c, ss, cc, u, v;
/* if Y1(NaN) is NaN, Y1(-inf) is NaN, Y1(inf) is 0 */
if (!finite(x))
- if (!_IEEE) return (infnan(EDOM));
- else if (x < 0)
+ if (x < 0)
return(zero/zero);
else if (x > 0)
return (0);
diff --git a/lib/libm/noieee_src/n_jn.c b/lib/libm/noieee_src/n_jn.c
index f6458dc71b4..5383aa35b34 100644
--- a/lib/libm/noieee_src/n_jn.c
+++ b/lib/libm/noieee_src/n_jn.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: n_jn.c,v 1.5 2008/06/21 08:26:19 martynas Exp $ */
+/* $OpenBSD: n_jn.c,v 1.6 2008/06/25 17:49:31 martynas Exp $ */
/* $NetBSD: n_jn.c,v 1.1 1995/10/10 23:36:54 ragge Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -260,7 +260,7 @@ yn(int n, double x)
double a, b, temp;
/* Y(n,NaN), Y(n, x < 0) is NaN */
- if (x <= 0 || (_IEEE && x != x))
+ if (x <= 0 || isnan(x))
if (_IEEE && x < 0) return zero/zero;
else if (x < 0) return (infnan(EDOM));
else if (_IEEE) return -one/zero;
diff --git a/lib/libm/noieee_src/n_pow.c b/lib/libm/noieee_src/n_pow.c
index 9c44bfe2728..2801a4b0b63 100644
--- a/lib/libm/noieee_src/n_pow.c
+++ b/lib/libm/noieee_src/n_pow.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: n_pow.c,v 1.9 2008/06/21 08:26:19 martynas Exp $ */
+/* $OpenBSD: n_pow.c,v 1.10 2008/06/25 17:49:31 martynas Exp $ */
/* $NetBSD: n_pow.c,v 1.1 1995/10/10 23:37:02 ragge Exp $ */
/*
* Copyright (c) 1985, 1993
@@ -44,7 +44,7 @@ static char sccsid[] = "@(#)pow.c 8.1 (Berkeley) 6/4/93";
* logb(x)
* copysign(x,y)
* finite(x)
- * drem(x,y)
+ * remainder(x,y)
*
* Required kernel functions:
* exp__D(a,c) exp(a + c) for |a| << |c|
@@ -127,9 +127,9 @@ pow(double x, double y)
double t;
if (y==zero)
return (one);
- else if (y==one || (_IEEE && x != x))
+ else if (y==one || isnan(x))
return (x); /* if x is NaN or y=1 */
- else if (_IEEE && y!=y) /* if y is NaN */
+ else if (isnan(y)) /* if y is NaN */
return (y);
else if (!finite(y)) /* if y is INF */
if ((t=fabs(x))==one) /* +-1 ** +-INF is NaN */
@@ -148,7 +148,7 @@ pow(double x, double y)
/* sign(x)= -1 */
/* if y is an even integer */
- else if ( (t=drem(y,two)) == zero)
+ else if ( (t=remainder(y,two)) == zero)
return (pow_P(-x, y));
/* if y is an odd integer */
diff --git a/lib/libm/noieee_src/n_sincos.c b/lib/libm/noieee_src/n_sincos.c
index 8cd26b5139f..44627cd2bc5 100644
--- a/lib/libm/noieee_src/n_sincos.c
+++ b/lib/libm/noieee_src/n_sincos.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: n_sincos.c,v 1.5 2008/06/21 08:26:19 martynas Exp $ */
+/* $OpenBSD: n_sincos.c,v 1.6 2008/06/25 17:49:31 martynas Exp $ */
/* $NetBSD: n_sincos.c,v 1.1 1995/10/10 23:37:04 ragge Exp $ */
/*
* Copyright (c) 1987, 1993
@@ -43,7 +43,7 @@ sin(double x)
if(!finite(x)) /* sin(NaN) and sin(INF) must be NaN */
return x-x;
- x=drem(x,PI2); /* reduce x into [-PI,PI] */
+ x=remainder(x,PI2); /* reduce x into [-PI,PI] */
a=copysign(x,one);
if (a >= PIo4) {
if(a >= PI3o4) /* ... in [3PI/4,PI] */
@@ -72,7 +72,7 @@ cos(double x)
if(!finite(x)) /* cos(NaN) and cos(INF) must be NaN */
return x-x;
- x=drem(x,PI2); /* reduce x into [-PI,PI] */
+ x=remainder(x,PI2); /* reduce x into [-PI,PI] */
a=copysign(x,one);
if (a >= PIo4) {
if (a >= PI3o4) { /* ... in [3PI/4,PI] */
diff --git a/lib/libm/noieee_src/n_support.c b/lib/libm/noieee_src/n_support.c
index 2c41c767f0a..a9449a1164d 100644
--- a/lib/libm/noieee_src/n_support.c
+++ b/lib/libm/noieee_src/n_support.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: n_support.c,v 1.10 2008/06/21 08:26:19 martynas Exp $ */
+/* $OpenBSD: n_support.c,v 1.11 2008/06/25 17:49:31 martynas Exp $ */
/* $NetBSD: n_support.c,v 1.1 1995/10/10 23:37:06 ragge Exp $ */
/*
* Copyright (c) 1985, 1993
@@ -177,7 +177,7 @@ logb(double x)
return ( -1022.0 );
else
return(-(1.0/zero));
- else if(x != x)
+ else if(isnan(x))
return(x);
else
{*px &= msign; return(x);}
@@ -287,7 +287,7 @@ sqrt(double x)
#endif /* defined(__vax__) */
/* sqrt(NaN) is NaN, sqrt(+-0) = +-0 */
- if(x!=x||x==zero) return(x);
+ if(isnan(x) || x == zero) return(x);
/* sqrt(negative) is invalid */
if(x<zero) {
@@ -372,8 +372,8 @@ remainder(double x, double y)
sign = px[n0] &0x8000; /* sign of x */
/* return NaN if x is NaN, or y is NaN, or x is INF, or y is zero */
- if(x!=x) return(x); if(y!=y) return(y); /* x or y is NaN */
- if( xexp == mexp ) return(zero/zero); /* x is INF */
+ if(isnan(x)) return(x); if(isnan(y)) return(y); /* x or y is NaN */
+ if( xexp == mexp ) return(zero/zero); /* x is INF */
if(y==zero) return(y/y);
/* save the inexact flag and inexact enable in i and e respectively
@@ -470,7 +470,8 @@ newsqrt(double x)
*/
/* exceptions */
- if(x!=x||x==0.0) return(x); /* sqrt(NaN) is NaN, sqrt(+-0) = +-0 */
+ if(isnan(x) || x == 0.0) return(x); /* sqrt(NaN) is NaN,
+ sqrt(+-0) = +-0 */
if(x<0) return((x-x)/(x-x)); /* sqrt(negative) is invalid */
if((mx=px[n0]&mexp)==mexp) return(x); /* sqrt(+INF) is +INF */
diff --git a/lib/libm/noieee_src/n_tan.c b/lib/libm/noieee_src/n_tan.c
index 61014e21033..bd3d97b96ef 100644
--- a/lib/libm/noieee_src/n_tan.c
+++ b/lib/libm/noieee_src/n_tan.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: n_tan.c,v 1.5 2008/06/21 08:26:19 martynas Exp $ */
+/* $OpenBSD: n_tan.c,v 1.6 2008/06/25 17:49:31 martynas Exp $ */
/* $NetBSD: n_tan.c,v 1.1 1995/10/10 23:37:07 ragge Exp $ */
/*
* Copyright (c) 1987, 1993
@@ -44,8 +44,8 @@ tan(double x)
if(!finite(x)) /* tan(NaN) and tan(INF) must be NaN */
return x-x;
- x = drem(x,PI); /* reduce x into [-PI/2, PI/2] */
- a = copysign(x,one); /* ... = abs(x) */
+ x = remainder(x,PI); /* reduce x into [-PI/2, PI/2] */
+ a = copysign(x,one); /* ... = abs(x) */
if (a >= PIo4) {
k = 1;
x = copysign(PIo2-a,x);