summaryrefslogtreecommitdiff
path: root/lib/msun/src
diff options
context:
space:
mode:
authorDavid Schultz <das@FreeBSD.org>2004-07-09 03:32:40 +0000
committerDavid Schultz <das@FreeBSD.org>2004-07-09 03:32:40 +0000
commit240dbabfa8e8f13bf761868a69f3045a8bc474ab (patch)
tree5275f48bb8c8196ab5e9ffc78ef28924e9a8a56f /lib/msun/src
parentb2d5d0b376f77ab02352cf8291f7598fa71bb40a (diff)
Notes
Diffstat (limited to 'lib/msun/src')
-rw-r--r--lib/msun/src/math.h34
-rw-r--r--lib/msun/src/s_isfinite.c58
-rw-r--r--lib/msun/src/s_isnormal.c58
3 files changed, 144 insertions, 6 deletions
diff --git a/lib/msun/src/math.h b/lib/msun/src/math.h
index 754599e2ff04..92dfd23cedf1 100644
--- a/lib/msun/src/math.h
+++ b/lib/msun/src/math.h
@@ -79,10 +79,22 @@ extern const union __nan_un {
: (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 isnormal(x) (fpclassify(x) == FP_NORMAL)
+#define isfinite(x) \
+ ((sizeof (x) == sizeof (float)) ? __isfinitef(x) \
+ : (sizeof (x) == sizeof (double)) ? __isfinite(x) \
+ : __isfinitel(x))
+#define isinf(x) \
+ ((sizeof (x) == sizeof (float)) ? __isinff(x) \
+ : (sizeof (x) == sizeof (double)) ? isinf(x) \
+ : __isinfl(x))
+#define isnan(x) \
+ ((sizeof (x) == sizeof (float)) ? isnanf(x) \
+ : (sizeof (x) == sizeof (double)) ? isnan(x) \
+ : __isnanl(x))
+#define isnormal(x) \
+ ((sizeof (x) == sizeof (float)) ? __isnormalf(x) \
+ : (sizeof (x) == sizeof (double)) ? __isnormal(x) \
+ : __isnormall(x))
#ifdef __MATH_BUILTIN_RELOPS
#define isgreater(x, y) __builtin_isgreater((x), (y))
@@ -161,8 +173,6 @@ struct exception {
};
#endif
-#define isnanf(x) isnan(x)
-
#if 0
/* Old value from 4.4BSD-Lite math.h; this is probably better. */
#define HUGE HUGE_VAL
@@ -195,6 +205,15 @@ __BEGIN_DECLS
int __fpclassifyd(double) __pure2;
int __fpclassifyf(float) __pure2;
int __fpclassifyl(long double) __pure2;
+int __isfinitef(float) __pure2;
+int __isfinite(double) __pure2;
+int __isfinitel(long double) __pure2;
+int __isinff(float) __pure2;
+int __isinfl(long double) __pure2;
+int __isnanl(long double) __pure2;
+int __isnormalf(float) __pure2;
+int __isnormal(double) __pure2;
+int __isnormall(long double) __pure2;
int __signbit(double) __pure2;
double acos(double);
@@ -241,6 +260,8 @@ double fmax(double, double) __pure2;
double fmin(double, double) __pure2;
double hypot(double, double);
int ilogb(double);
+int (isinf)(double) __pure2;
+int (isnan)(double) __pure2;
double lgamma(double);
double log1p(double) __pure2;
double logb(double) __pure2;
@@ -279,6 +300,7 @@ double tgamma(double);
#if __BSD_VISIBLE
double drem(double, double);
int finite(double) __pure2;
+int isnanf(float) __pure2;
/*
* Reentrant version of gamma & lgamma; passes signgam back by reference
diff --git a/lib/msun/src/s_isfinite.c b/lib/msun/src/s_isfinite.c
new file mode 100644
index 000000000000..c9d1bd7a1347
--- /dev/null
+++ b/lib/msun/src/s_isfinite.c
@@ -0,0 +1,58 @@
+/*-
+ * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <math.h>
+
+#include "fpmath.h"
+
+int
+__isfinite(double d)
+{
+ union IEEEd2bits u;
+
+ u.d = d;
+ return (u.bits.exp != 2047);
+}
+
+int
+__isfinitef(float f)
+{
+ union IEEEf2bits u;
+
+ u.f = f;
+ return (u.bits.exp != 255);
+}
+
+int
+__isfinitel(long double e)
+{
+ union IEEEl2bits u;
+
+ u.e = e;
+ return (u.bits.exp != 32767);
+}
diff --git a/lib/msun/src/s_isnormal.c b/lib/msun/src/s_isnormal.c
new file mode 100644
index 000000000000..49f2a74346b3
--- /dev/null
+++ b/lib/msun/src/s_isnormal.c
@@ -0,0 +1,58 @@
+/*-
+ * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <math.h>
+
+#include "fpmath.h"
+
+int
+__isnormal(double d)
+{
+ union IEEEd2bits u;
+
+ u.d = d;
+ return (u.bits.exp != 0 && u.bits.exp != 2047);
+}
+
+int
+__isnormalf(float f)
+{
+ union IEEEf2bits u;
+
+ u.f = f;
+ return (u.bits.exp != 0 && u.bits.exp != 255);
+}
+
+int
+__isnormall(long double e)
+{
+ union IEEEl2bits u;
+
+ u.e = e;
+ return (u.bits.exp != 0 && u.bits.exp != 32767);
+}