summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authordas <das@FreeBSD.org>2004-07-09 03:32:40 +0000
committerdas <das@FreeBSD.org>2004-07-09 03:32:40 +0000
commit65d8d759b1ed37f98e49000925a5e89487cf95fd (patch)
tree5275f48bb8c8196ab5e9ffc78ef28924e9a8a56f /lib
parent5ef7c3d0ff72cc97a9a5ed0935c3a12630e46b1b (diff)
downloadFreeBSD-src-65d8d759b1ed37f98e49000925a5e89487cf95fd.zip
FreeBSD-src-65d8d759b1ed37f98e49000925a5e89487cf95fd.tar.gz
Implement the classification macros isfinite(), isinf(), isnan(), and
isnormal() the hard way, rather than relying on fpclassify(). This is a lose in the sense that we need a total of 12 functions, but it is necessary for binary compatibility because we have never bumped libm's major version number. In particular, isinf(), isnan(), and isnanf() were BSD libc functions before they were C99 macros, so we can't reimplement them in terms of fpclassify() without adding a dependency on libc.so.5. I have tried to arrange things so that programs that could be compiled in FreeBSD 4.X will generate the same external references when compiled in 5.X. At the same time, the new macros should remain C99-compliant. The isinf() and isnan() functions remain in libc for historical reasons; however, I have moved the functions that implement the macros isfinite() and isnormal() to libm where they belong. Moreover, half a dozen MD versions of isinf() and isnan() have been replaced with MI versions that work equally well. Prodded by: kris
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/alpha/gen/Makefile.inc2
-rw-r--r--lib/libc/alpha/gen/isinf.c68
-rw-r--r--lib/libc/amd64/gen/Makefile.inc2
-rw-r--r--lib/libc/amd64/gen/isinf.c75
-rw-r--r--lib/libc/arm/gen/Makefile.inc2
-rw-r--r--lib/libc/arm/gen/isinf.c70
-rw-r--r--lib/libc/gen/Makefile.inc2
-rw-r--r--lib/libc/gen/isinf.c66
-rw-r--r--lib/libc/gen/isnan.c67
-rw-r--r--lib/libc/i386/gen/Makefile.inc2
-rw-r--r--lib/libc/i386/gen/isinf.c75
-rw-r--r--lib/libc/ia64/gen/Makefile.inc3
-rw-r--r--lib/libc/ia64/gen/isinf.c68
-rw-r--r--lib/libc/powerpc/gen/Makefile.inc2
-rw-r--r--lib/libc/powerpc/gen/isinf.c67
-rw-r--r--lib/libc/sparc64/gen/Makefile.inc2
-rw-r--r--lib/libc/sparc64/gen/isinf.c69
-rw-r--r--lib/msun/Makefile3
-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
21 files changed, 287 insertions, 508 deletions
diff --git a/lib/libc/alpha/gen/Makefile.inc b/lib/libc/alpha/gen/Makefile.inc
index 39292c4..11950b2 100644
--- a/lib/libc/alpha/gen/Makefile.inc
+++ b/lib/libc/alpha/gen/Makefile.inc
@@ -1,6 +1,6 @@
# $FreeBSD$
-SRCS+= _setjmp.S fabs.S frexp.c infinity.c isinf.c ldexp.c modf.c setjmp.S
+SRCS+= _setjmp.S fabs.S frexp.c infinity.c ldexp.c modf.c setjmp.S
SRCS+= flt_rounds.c fpgetmask.c fpgetround.c fpgetsticky.c fpsetmask.c \
fpsetround.c fpsetsticky.c
diff --git a/lib/libc/alpha/gen/isinf.c b/lib/libc/alpha/gen/isinf.c
deleted file mode 100644
index df6ac96..0000000
--- a/lib/libc/alpha/gen/isinf.c
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (c) 1994, 1995 Carnegie-Mellon University.
- * All rights reserved.
- *
- * Author: Chris G. Demetriou
- *
- * Permission to use, copy, modify and distribute this software and
- * its documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
- * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
- * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * Carnegie Mellon requests users of this software to return to
- *
- * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
- * School of Computer Science
- * Carnegie Mellon University
- * Pittsburgh PA 15213-3890
- *
- * any improvements or extensions that they make and grant Carnegie the
- * rights to redistribute these changes.
- *
- * $NetBSD: isinf.c,v 1.1 1995/02/10 17:50:23 cgd Exp $
- */
-
-/* For binary compat; to be removed in FreeBSD 6.0. */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <machine/ieee.h>
-#include <math.h>
-
-#undef isnan
-#undef isinf
-
-int
-isnan(d)
- double d;
-{
- union {
- double v;
- struct ieee_double s;
- } u;
-
- u.v = d;
- return (u.s.dbl_exp == DBL_EXP_INFNAN &&
- (u.s.dbl_frach || u.s.dbl_fracl));
-}
-
-int
-isinf(d)
- double d;
-{
- union {
- double v;
- struct ieee_double s;
- } u;
-
- u.v = d;
- return (u.s.dbl_exp == DBL_EXP_INFNAN &&
- !u.s.dbl_frach && !u.s.dbl_fracl);
-}
diff --git a/lib/libc/amd64/gen/Makefile.inc b/lib/libc/amd64/gen/Makefile.inc
index 053c9c9..2caa178 100644
--- a/lib/libc/amd64/gen/Makefile.inc
+++ b/lib/libc/amd64/gen/Makefile.inc
@@ -3,7 +3,7 @@
SRCS+= _setjmp.S rfork_thread.S setjmp.S sigsetjmp.S \
fabs.S modf.S \
- frexp.c infinity.c isinf.c ldexp.c \
+ frexp.c infinity.c ldexp.c \
makecontext.c signalcontext.c \
fpgetmask.c fpsetmask.c fpgetprec.c fpsetprec.c \
fpgetround.c fpsetround.c fpgetsticky.c fpsetsticky.c
diff --git a/lib/libc/amd64/gen/isinf.c b/lib/libc/amd64/gen/isinf.c
deleted file mode 100644
index a5e9dec..0000000
--- a/lib/libc/amd64/gen/isinf.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. 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.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
- */
-
-/* For binary compat; to be removed in FreeBSD 6.0. */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)isinf.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-
-struct IEEEdp {
- u_int manl : 32;
- u_int manh : 20;
- u_int exp : 11;
- u_int sign : 1;
-};
-
-int
-isnan(d)
- double d;
-{
- union {
- double v;
- struct IEEEdp s;
- } u;
-
- u.v = d;
- return(u.s.exp == 2047 && (u.s.manh || u.s.manl));
-}
-
-int
-isinf(d)
- double d;
-{
- union {
- double v;
- struct IEEEdp s;
- } u;
-
- u.v = d;
- return(u.s.exp == 2047 && !u.s.manh && !u.s.manl);
-}
diff --git a/lib/libc/arm/gen/Makefile.inc b/lib/libc/arm/gen/Makefile.inc
index d34fcf7..e598d34 100644
--- a/lib/libc/arm/gen/Makefile.inc
+++ b/lib/libc/arm/gen/Makefile.inc
@@ -2,5 +2,5 @@
# $FreeBSD$
SRCS+= _ctx_start.S _setjmp.S alloca.S fabs.c frexp.c \
- infinity.c isinf.c ldexp.c makecontext.c modf.c \
+ infinity.c ldexp.c makecontext.c modf.c \
setjmp.S signalcontext.c sigsetjmp.S divsi3.S
diff --git a/lib/libc/arm/gen/isinf.c b/lib/libc/arm/gen/isinf.c
deleted file mode 100644
index d894b4f..0000000
--- a/lib/libc/arm/gen/isinf.c
+++ /dev/null
@@ -1,70 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. 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.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
- */
-
-/* For binary compat; to be removed in FreeBSD 6.0. */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)isinf.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-
-int
-isnan(d)
- double d;
-{
- register struct IEEEdp {
- u_int manl : 32;
- u_int manh : 20;
- u_int exp : 11;
- u_int sign : 1;
- } *p = (struct IEEEdp *)&d;
-
- return(p->exp == 2047 && (p->manh || p->manl));
-}
-
-int
-isinf(d)
- double d;
-{
- register struct IEEEdp {
- u_int manl : 32;
- u_int manh : 20;
- u_int exp : 11;
- u_int sign : 1;
- } *p = (struct IEEEdp *)&d;
-
- return(p->exp == 2047 && !p->manh && !p->manl);
-}
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc
index a7d164b..3f71b98 100644
--- a/lib/libc/gen/Makefile.inc
+++ b/lib/libc/gen/Makefile.inc
@@ -17,7 +17,7 @@ SRCS+= __xuname.c _pthread_stubs.c _rand48.c _spinlock_stub.c _thread_init.c \
getobjformat.c getosreldate.c getpagesize.c \
getpeereid.c getprogname.c getpwent.c getttyent.c \
getusershell.c getvfsbyname.c glob.c \
- initgroups.c isatty.c jrand48.c lcong48.c \
+ initgroups.c isatty.c isinf.c isnan.c jrand48.c lcong48.c \
lockf.c lrand48.c mrand48.c nice.c \
nlist.c nrand48.c ntp_gettime.c opendir.c \
pause.c pmadvise.c popen.c posixshm.c pselect.c \
diff --git a/lib/libc/gen/isinf.c b/lib/libc/gen/isinf.c
new file mode 100644
index 0000000..248fc93
--- /dev/null
+++ b/lib/libc/gen/isinf.c
@@ -0,0 +1,66 @@
+/*-
+ * 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"
+
+/*
+ * XXX These routines belong in libm, but they must remain in libc for
+ * binary compat until we can bump libm's major version number.
+ */
+
+__weak_reference(__isinf, isinf);
+
+int
+__isinf(double d)
+{
+ union IEEEd2bits u;
+
+ u.d = d;
+ return (u.bits.exp == 2047 && u.bits.manl == 0 && u.bits.manh == 0);
+}
+
+int
+__isinff(float f)
+{
+ union IEEEf2bits u;
+
+ u.f = f;
+ return (u.bits.exp == 255 && u.bits.man == 0);
+}
+
+int
+__isinfl(long double e)
+{
+ union IEEEl2bits u;
+
+ u.e = e;
+ mask_nbit_l(u);
+ return (u.bits.exp == 32767 && u.bits.manl == 0 && u.bits.manh == 0);
+}
diff --git a/lib/libc/gen/isnan.c b/lib/libc/gen/isnan.c
new file mode 100644
index 0000000..52cec1b
--- /dev/null
+++ b/lib/libc/gen/isnan.c
@@ -0,0 +1,67 @@
+/*-
+ * 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"
+
+/*
+ * XXX These routines belong in libm, but they must remain in libc for
+ * binary compat until we can bump libm's major version number.
+ */
+
+__weak_reference(__isnan, isnan);
+__weak_reference(__isnanf, isnanf);
+
+int
+__isnan(double d)
+{
+ union IEEEd2bits u;
+
+ u.d = d;
+ return (u.bits.exp == 2047 && (u.bits.manl != 0 || u.bits.manh != 0));
+}
+
+int
+__isnanf(float f)
+{
+ union IEEEf2bits u;
+
+ u.f = f;
+ return (u.bits.exp == 255 && u.bits.man != 0);
+}
+
+int
+__isnanl(long double e)
+{
+ union IEEEl2bits u;
+
+ u.e = e;
+ mask_nbit_l(u);
+ return (u.bits.exp == 32767 && (u.bits.manl != 0 || u.bits.manh != 0));
+}
diff --git a/lib/libc/i386/gen/Makefile.inc b/lib/libc/i386/gen/Makefile.inc
index 2761608..624ec54 100644
--- a/lib/libc/i386/gen/Makefile.inc
+++ b/lib/libc/i386/gen/Makefile.inc
@@ -2,5 +2,5 @@
# $FreeBSD$
SRCS+= _ctx_start.S _setjmp.S alloca.S fabs.S frexp.c \
- infinity.c isinf.c ldexp.c makecontext.c modf.S \
+ infinity.c ldexp.c makecontext.c modf.S \
rfork_thread.S setjmp.S signalcontext.c sigsetjmp.S
diff --git a/lib/libc/i386/gen/isinf.c b/lib/libc/i386/gen/isinf.c
deleted file mode 100644
index 0d9cd86..0000000
--- a/lib/libc/i386/gen/isinf.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. 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.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
- */
-
-/* For binary compat; to be removed in FreeBSD 6.0. */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)isinf.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-
-struct IEEEdp {
- u_int manl : 32;
- u_int manh : 20;
- u_int exp : 11;
- u_int sign : 1;
-};
-
-int
-isnan(d)
- double d;
-{
- union {
- double v;
- struct IEEEdp s;
- } u;
-
- u.v = d;
- return (u.s.exp == 2047 && (u.s.manh || u.s.manl));
-}
-
-int
-isinf(d)
- double d;
-{
- union {
- double v;
- struct IEEEdp s;
- } u;
-
- u.v = d;
- return (u.s.exp == 2047 && !u.s.manh && !u.s.manl);
-}
diff --git a/lib/libc/ia64/gen/Makefile.inc b/lib/libc/ia64/gen/Makefile.inc
index 91d54fd..3f68eeb 100644
--- a/lib/libc/ia64/gen/Makefile.inc
+++ b/lib/libc/ia64/gen/Makefile.inc
@@ -3,8 +3,7 @@
SRCS+= __divdf3.S __divdi3.S __divsf3.S __divsi3.S __moddi3.S __modsi3.S \
__udivdi3.S __udivsi3.S __umoddi3.S __umodsi3.S _setjmp.S fabs.S \
fpgetmask.c fpgetround.c fpsetmask.c fpsetround.c frexp.c infinity.c \
- isinf.c ldexp.c makecontext.c modf.c setjmp.S signalcontext.c \
- sigsetjmp.S
+ ldexp.c makecontext.c modf.c setjmp.S signalcontext.c sigsetjmp.S
# The following may go away if function _Unwind_FindTableEntry()
# will be part of GCC.
diff --git a/lib/libc/ia64/gen/isinf.c b/lib/libc/ia64/gen/isinf.c
deleted file mode 100644
index 8f346f3..0000000
--- a/lib/libc/ia64/gen/isinf.c
+++ /dev/null
@@ -1,68 +0,0 @@
-/* $NetBSD: isinf.c,v 1.1 1995/02/10 17:50:23 cgd Exp $ */
-
-/*
- * Copyright (c) 1994, 1995 Carnegie-Mellon University.
- * All rights reserved.
- *
- * Author: Chris G. Demetriou
- *
- * Permission to use, copy, modify and distribute this software and
- * its documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
- * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
- * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * Carnegie Mellon requests users of this software to return to
- *
- * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
- * School of Computer Science
- * Carnegie Mellon University
- * Pittsburgh PA 15213-3890
- *
- * any improvements or extensions that they make and grant Carnegie the
- * rights to redistribute these changes.
- */
-
-/* For binary compat; to be removed in FreeBSD 6.0. */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <machine/ieee.h>
-#include <math.h>
-
-#undef isnan
-#undef isinf
-
-int
-isnan(d)
- double d;
-{
- union {
- double v;
- struct ieee_double s;
- } u;
-
- u.v = d;
- return (u.s.dbl_exp == DBL_EXP_INFNAN &&
- (u.s.dbl_frach || u.s.dbl_fracl));
-}
-
-int
-isinf(d)
- double d;
-{
- union {
- double v;
- struct ieee_double s;
- } u;
-
- u.v = d;
- return (u.s.dbl_exp == DBL_EXP_INFNAN &&
- !u.s.dbl_frach && !u.s.dbl_fracl);
-}
diff --git a/lib/libc/powerpc/gen/Makefile.inc b/lib/libc/powerpc/gen/Makefile.inc
index 8a431da..22689d7 100644
--- a/lib/libc/powerpc/gen/Makefile.inc
+++ b/lib/libc/powerpc/gen/Makefile.inc
@@ -2,7 +2,7 @@
SRCS += _ctx_start.S fabs.S flt_rounds.c fpgetmask.c fpgetround.c \
fpgetsticky.c fpsetmask.c fpsetround.c fpsetsticky.c frexp.c \
- infinity.c isinf.c ldexp.c makecontext.c modf.c _setjmp.S \
+ infinity.c ldexp.c makecontext.c modf.c _setjmp.S \
setjmp.S sigsetjmp.S syncicache.c
diff --git a/lib/libc/powerpc/gen/isinf.c b/lib/libc/powerpc/gen/isinf.c
deleted file mode 100644
index 0b9ef6c..0000000
--- a/lib/libc/powerpc/gen/isinf.c
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (c) 1994, 1995 Carnegie-Mellon University.
- * All rights reserved.
- *
- * Author: Chris G. Demetriou
- *
- * Permission to use, copy, modify and distribute this software and
- * its documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
- * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
- * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * Carnegie Mellon requests users of this software to return to
- *
- * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
- * School of Computer Science
- * Carnegie Mellon University
- * Pittsburgh PA 15213-3890
- *
- * any improvements or extensions that they make and grant Carnegie the
- * rights to redistribute these changes.
- *
- * $NetBSD: isinf.c,v 1.1 1995/02/10 17:50:23 cgd Exp $
- * from: FreeBSD: src/lib/libc/alpha/gen/isinf.c,v 1.2 2000/05/10
- */
-
-/* For binary compat; to be removed in FreeBSD 6.0. */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <machine/ieee.h>
-#include <math.h>
-
-#undef isnan
-#undef isinf
-
-int
-isnan(double d)
-{
- union {
- double v;
- struct ieee_double s;
- } u;
-
- u.v = d;
- return (u.s.dbl_exp == DBL_EXP_INFNAN &&
- (u.s.dbl_frach || u.s.dbl_fracl));
-}
-
-int
-isinf(double d)
-{
- union {
- double v;
- struct ieee_double s;
- } u;
-
- u.v = d;
- return (u.s.dbl_exp == DBL_EXP_INFNAN &&
- !u.s.dbl_frach && !u.s.dbl_fracl);
-}
diff --git a/lib/libc/sparc64/gen/Makefile.inc b/lib/libc/sparc64/gen/Makefile.inc
index 265f3c0..789f95ac 100644
--- a/lib/libc/sparc64/gen/Makefile.inc
+++ b/lib/libc/sparc64/gen/Makefile.inc
@@ -2,5 +2,5 @@
SRCS+= _ctx_start.S _setjmp.S fabs.S fixunsdfsi.S flt_rounds.c fpgetmask.c \
fpgetround.c fpgetsticky.c fpsetmask.c fpsetround.c fpsetsticky.c \
- frexp.c infinity.c isinf.c ldexp.c makecontext.c modf.S \
+ frexp.c infinity.c ldexp.c makecontext.c modf.S \
signalcontext.c setjmp.S sigsetjmp.S
diff --git a/lib/libc/sparc64/gen/isinf.c b/lib/libc/sparc64/gen/isinf.c
deleted file mode 100644
index 0cbdfff..0000000
--- a/lib/libc/sparc64/gen/isinf.c
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (c) 1994, 1995 Carnegie-Mellon University.
- * All rights reserved.
- *
- * Author: Chris G. Demetriou
- *
- * Permission to use, copy, modify and distribute this software and
- * its documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
- * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
- * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * Carnegie Mellon requests users of this software to return to
- *
- * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
- * School of Computer Science
- * Carnegie Mellon University
- * Pittsburgh PA 15213-3890
- *
- * any improvements or extensions that they make and grant Carnegie the
- * rights to redistribute these changes.
- *
- * $NetBSD: isinf.c,v 1.1 1995/02/10 17:50:23 cgd Exp $
- * from: FreeBSD: src/lib/libc/alpha/gen/isinf.c,v 1.2 2000/05/10
- */
-
-/* For binary compat; to be removed in FreeBSD 6.0. */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <machine/ieee.h>
-#include <math.h>
-
-#undef isnan
-#undef isinf
-
-int
-isnan(d)
- double d;
-{
- union {
- double v;
- struct ieee_double s;
- } u;
-
- u.v = d;
- return (u.s.dbl_exp == DBL_EXP_INFNAN &&
- (u.s.dbl_frach || u.s.dbl_fracl));
-}
-
-int
-isinf(d)
- double d;
-{
- union {
- double v;
- struct ieee_double s;
- } u;
-
- u.v = d;
- return (u.s.dbl_exp == DBL_EXP_INFNAN &&
- !u.s.dbl_frach && !u.s.dbl_fracl);
-}
diff --git a/lib/msun/Makefile b/lib/msun/Makefile
index 9dc02e3..85813ff 100644
--- a/lib/msun/Makefile
+++ b/lib/msun/Makefile
@@ -84,7 +84,8 @@ COMMON_SRCS= b_exp.c b_log.c b_tgamma.c \
s_expm1.c s_expm1f.c s_fabsf.c s_fdim.c s_finite.c s_finitef.c \
s_floor.c s_floorf.c s_fmax.c s_fmaxf.c s_fmaxl.c s_fmin.c \
s_fminf.c s_fminl.c s_frexp.c s_frexpf.c s_ilogb.c s_ilogbf.c \
- s_isnanf.c s_ldexpf.c s_lib_version.c s_log1p.c \
+ s_isfinite.c s_isnanf.c s_isnormal.c s_ldexpf.c \
+ s_lib_version.c s_log1p.c \
s_log1pf.c s_logb.c s_logbf.c s_matherr.c s_modff.c \
s_nearbyint.c s_nextafter.c s_nextafterf.c \
s_rint.c s_rintf.c s_round.c s_roundf.c \
diff --git a/lib/msun/src/math.h b/lib/msun/src/math.h
index 754599e..92dfd23 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 0000000..c9d1bd7
--- /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 0000000..49f2a74
--- /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);
+}
OpenPOWER on IntegriCloud