summaryrefslogtreecommitdiffstats
path: root/lib/msun
diff options
context:
space:
mode:
authormike <mike@FreeBSD.org>2003-02-12 20:03:41 +0000
committermike <mike@FreeBSD.org>2003-02-12 20:03:41 +0000
commit1998abeb23dab7b75455dd4404b6c6e65f3f5d17 (patch)
treedcd3e60930c7e038a326f0d2956c397a380c5f93 /lib/msun
parenta6f0140de945f637820ecc83d9a6fa9f9c999926 (diff)
downloadFreeBSD-src-1998abeb23dab7b75455dd4404b6c6e65f3f5d17.zip
FreeBSD-src-1998abeb23dab7b75455dd4404b6c6e65f3f5d17.tar.gz
o Implement C99 classification macros isfinite(), isinf(), isnan(),
isnormal(). The current isinf() and isnan() are perserved for binary compatibility with 5.0, but new programs will use the macros. o Implement C99 comparison macros isgreater(), isgreaterequal(), isless(), islessequal(), islessgreater(), isunordered(). Submitted by: David Schultz <dschultz@uclink.Berkeley.EDU>
Diffstat (limited to 'lib/msun')
-rw-r--r--lib/msun/src/math.h36
-rw-r--r--lib/msun/src/s_isnan.c4
-rw-r--r--lib/msun/src/s_isnanf.c4
3 files changed, 32 insertions, 12 deletions
diff --git a/lib/msun/src/math.h b/lib/msun/src/math.h
index b902df1..2bb06c5 100644
--- a/lib/msun/src/math.h
+++ b/lib/msun/src/math.h
@@ -41,15 +41,30 @@ extern const union __nan_un {
#define NAN (__nan.__uf)
/* Symbolic constants to classify floating point numbers. */
-#define FP_INFINITE 1
-#define FP_NAN 2
-#define FP_NORMAL 3
-#define FP_SUBNORMAL 4
-#define FP_ZERO 5
+#define FP_INFINITE 0x01
+#define FP_NAN 0x02
+#define FP_NORMAL 0x04
+#define FP_SUBNORMAL 0x08
+#define FP_ZERO 0x10
#define fpclassify(x) \
((sizeof (x) == sizeof (float)) ? __fpclassifyf(x) \
: (sizeof (x) == sizeof (double)) ? __fpclassifyd(x) \
: __fpclassifyl(x))
+
+#define isfinite(x) (fpclassify(x) & (FP_INFINITE|FP_NAN) == 0)
+#define isinf(x) (fpclassify(x) == FP_INFINITE)
+#define isnan(x) (fpclassify(x) == FP_NAN)
+#define isnanf(x) isnan(x)
+#define isnormal(x) (fpclassify(x) == FP_NORMAL)
+
+#define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y))
+#define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y))
+#define isless(x, y) (!isunordered((x), (y)) && (x) < (y))
+#define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y))
+#define islessgreater(x, y) (!isunordered((x), (y)) && \
+ ((x) > (y) || (y) > (x)))
+#define isunordered(x, y) (isnan(x) || isnan(y))
+
#define signbit(x) __signbit(x)
typedef __double_t double_t;
@@ -145,10 +160,10 @@ __BEGIN_DECLS
/*
* ANSI/POSIX
*/
-int __fpclassifyd(double);
-int __fpclassifyf(float);
-int __fpclassifyl(long double);
-int __signbit(double);
+int __fpclassifyd(double) __pure2;
+int __fpclassifyf(float) __pure2;
+int __fpclassifyl(long double) __pure2;
+int __signbit(double) __pure2;
double acos(double);
double asin(double);
@@ -187,8 +202,6 @@ double erfc(double) __pure2;
int finite(double) __pure2;
double gamma(double);
double hypot(double, double);
-int isinf(double) __pure2;
-int isnan(double) __pure2;
double j0(double);
double j1(double);
double jn(int, double);
@@ -274,7 +287,6 @@ float erfcf(float) __pure2;
int finitef(float) __pure2;
float gammaf(float);
float hypotf(float, float) __pure2;
-int isnanf(float) __pure2;
float j0f(float);
float j1f(float);
float jnf(int, float);
diff --git a/lib/msun/src/s_isnan.c b/lib/msun/src/s_isnan.c
index 3122a1e..bd1f6c9 100644
--- a/lib/msun/src/s_isnan.c
+++ b/lib/msun/src/s_isnan.c
@@ -10,6 +10,8 @@
* ====================================================
*/
+/* For binary compat; to be removed in FreeBSD 6.0. */
+
#ifndef lint
static char rcsid[] = "$FreeBSD$";
#endif
@@ -22,6 +24,8 @@ static char rcsid[] = "$FreeBSD$";
#include "math.h"
#include "math_private.h"
+#undef isnan
+
int isnan(double x)
{
int32_t hx,lx;
diff --git a/lib/msun/src/s_isnanf.c b/lib/msun/src/s_isnanf.c
index b1444cd..4e6e7b2 100644
--- a/lib/msun/src/s_isnanf.c
+++ b/lib/msun/src/s_isnanf.c
@@ -13,6 +13,8 @@
* ====================================================
*/
+/* For binary compat; to be removed in FreeBSD 6.0. */
+
#ifndef lint
static char rcsid[] = "$FreeBSD$";
#endif
@@ -25,6 +27,8 @@ static char rcsid[] = "$FreeBSD$";
#include "math.h"
#include "math_private.h"
+#undef isnanf
+
int isnanf(float x)
{
int32_t ix;
OpenPOWER on IntegriCloud