summaryrefslogtreecommitdiffstats
path: root/lib
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
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')
-rw-r--r--lib/libc/alpha/gen/isinf.c5
-rw-r--r--lib/libc/amd64/gen/isinf.c2
-rw-r--r--lib/libc/gen/Makefile.inc8
-rw-r--r--lib/libc/gen/fpclassify.364
-rw-r--r--lib/libc/gen/isgreater.3102
-rw-r--r--lib/libc/gen/isinf.380
-rw-r--r--lib/libc/i386/gen/isinf.c2
-rw-r--r--lib/libc/ia64/gen/isinf.c5
-rw-r--r--lib/libc/powerpc/gen/isinf.c5
-rw-r--r--lib/libc/sparc64/gen/isinf.c5
-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
13 files changed, 220 insertions, 102 deletions
diff --git a/lib/libc/alpha/gen/isinf.c b/lib/libc/alpha/gen/isinf.c
index 663154c..0017ea5 100644
--- a/lib/libc/alpha/gen/isinf.c
+++ b/lib/libc/alpha/gen/isinf.c
@@ -27,6 +27,8 @@
* $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$");
@@ -34,6 +36,9 @@ __FBSDID("$FreeBSD$");
#include <machine/ieee.h>
#include <math.h>
+#undef isnan
+#undef isinf
+
int
isnan(d)
double d;
diff --git a/lib/libc/amd64/gen/isinf.c b/lib/libc/amd64/gen/isinf.c
index e735cd4..d894b4f 100644
--- a/lib/libc/amd64/gen/isinf.c
+++ b/lib/libc/amd64/gen/isinf.c
@@ -31,6 +31,8 @@
* 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 */
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc
index c6ad6f2..43e0dc1 100644
--- a/lib/libc/gen/Makefile.inc
+++ b/lib/libc/gen/Makefile.inc
@@ -48,7 +48,7 @@ MAN+= alarm.3 arc4random.3 \
getmntinfo.3 getnetgrent.3 getobjformat.3 getosreldate.3 \
getpagesize.3 getpass.3 getpeereid.3 getprogname.3 getpwent.3 \
getttyent.3 getusershell.3 getvfsbyname.3 getvfsent.3 \
- glob.3 initgroups.3 isinf.3 ldexp.3 lockf.3 makecontext.3 \
+ glob.3 initgroups.3 isgreater.3 ldexp.3 lockf.3 makecontext.3 \
modf.3 msgctl.3 msgget.3 msgrcv.3 msgsnd.3 \
nice.3 nlist.3 pause.3 popen.3 pselect.3 psignal.3 pwcache.3 \
raise.3 rand48.3 readpassphrase.3 rfork_thread.3 \
@@ -72,6 +72,8 @@ MLINKS+=err.3 err_set_exit.3 err.3 err_set_file.3 err.3 errc.3 err.3 errx.3 \
err.3 vwarnx.3 err.3 warnc.3 err.3 warn.3 err.3 warnx.3
MLINKS+=exec.3 execl.3 exec.3 execle.3 exec.3 execlp.3 exec.3 exect.3 \
exec.3 execv.3 exec.3 execvp.3
+MLINKS+=fpclassify.3 isfinite.3 fpclassify.3 isinf.3 fpclassify.3 isnan.3 \
+ fpclassify.3 isnormal.3
MLINKS+=fts.3 fts_children.3 fts.3 fts_close.3 fts.3 fts_open.3 \
fts.3 fts_read.3 fts.3 fts_set.3
MLINKS+=getcap.3 cgetcap.3 getcap.3 cgetclose.3 getcap.3 cgetent.3 \
@@ -99,7 +101,9 @@ MLINKS+=getvfsent.3 endvfsent.3 getvfsent.3 getvfsbytype.3 \
getvfsent.3 setvfsent.3 getvfsent.3 vfsisloadable.3 \
getvfsent.3 vfsload.3
MLINKS+=glob.3 globfree.3
-MLINKS+=isinf.3 isnan.3 isinf.3 isnanf.3
+MLINKS+=isgreater.3 isgreaterequal.3 isgreater.3 isless.3 \
+ isgreater.3 islessequal.3 isgreater.3 islessgreater.3 \
+ isgreater.3 isunordered.3
MLINKS+=makecontext.3 swapcontext.3
MLINKS+=popen.3 pclose.3
MLINKS+=psignal.3 strsignal.3 psignal.3 sys_siglist.3 psignal.3 sys_signame.3
diff --git a/lib/libc/gen/fpclassify.3 b/lib/libc/gen/fpclassify.3
index 3ed831f..795887d 100644
--- a/lib/libc/gen/fpclassify.3
+++ b/lib/libc/gen/fpclassify.3
@@ -24,11 +24,11 @@
.\"
.\" $FreeBSD$
.\"
-.Dd February 8, 2003
+.Dd February 12, 2003
.Dt FPCLASSIFY 3
.Os
.Sh NAME
-.Nm fpclassify
+.Nm fpclassify , isfinite , isinf , isnan , isnormal
.Nd "classify a floating-point number"
.Sh LIBRARY
.Lb libc
@@ -36,6 +36,14 @@
.In math.h
.Ft int
.Fn fpclassify "real-floating x"
+.Ft int
+.Fn isfinite "real-floating x"
+.Ft int
+.Fn isinf "real-floating x"
+.Ft int
+.Fn isnan "real-floating x"
+.Ft int
+.Fn isnormal "real-floating x"
.Sh DESCRIPTION
The
.Fn fpclassify
@@ -64,18 +72,58 @@ Indicates that
.Va x
is zero (0 or -0).
.El
+.Pp
+The
+.Fn isfinite
+macro returns a non-zero value if and only if its argument has
+a finite (zero, subnormal, or normal) value. The
+.Fn isinf ,
+.Fn isnan ,
+and
+.Fn isnormal
+macros return non-zero if and only if
+.Va x
+is an infinity, NaN,
+or a non-zero normalized number, respectively.
+.Pp
+The symbol
+.Fn isnanf
+is provided as an alias to
+.Fn isnan
+for compatibility, and its use is deprecated.
.Sh SEE ALSO
-.Xr math 3
+.Xr isgreater 3 ,
+.Xr math 3 ,
+.Xr signbit 3
.Sh STANDARDS
The
-.Fn fpclassify
-macro conforms to
+.Fn fpclassify ,
+.Fn isfinite ,
+.Fn isinf ,
+.Fn isnan ,
+and
+.Fn isnormal
+macros conform to
.St -isoC-99 .
.Sh HISTORY
The
-.Fn fpclassify
-macro was added in
+.Fn fpclassify ,
+.Fn isfinite ,
+.Fn isinf ,
+.Fn isnan ,
+and
+.Fn isnormal
+macros were added in
.Fx 5.1 .
+.Bx 3
+introduced
+.Fn isinf
+and
+.Fn isnan
+functions, which accepted
+.Ft double
+arguments; these have been superseded by the macros
+described above.
.Sh BUGS
By default, the DEC Alpha architecture does not support IEEE rounding.
-See compiler documentation for additional details.
+See the compiler documentation for additional details.
diff --git a/lib/libc/gen/isgreater.3 b/lib/libc/gen/isgreater.3
new file mode 100644
index 0000000..6191047
--- /dev/null
+++ b/lib/libc/gen/isgreater.3
@@ -0,0 +1,102 @@
+.\" Copyright (c) 2003 David Schultz <dschultz@uclink.Berkeley.EDU>
+.\" 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$
+.\"
+.Dd February 12, 2003
+.Dt ISGREATER 3
+.Os
+.Sh NAME
+.Nm isgreater , isgreaterequal , isless , islessequal ,
+.Nm islessgreater , isunordered
+.Nd "compare two floating-point numbers"
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In math.h
+.Ft int
+.Fn isgreater "real-floating x" "real-floating y"
+.Ft int
+.Fn isgreaterequal "real-floating x" "real-floating y"
+.Ft int
+.Fn isless "real-floating x" "real-floating y"
+.Ft int
+.Fn islessequal "real-floating x" "real-floating y"
+.Ft int
+.Fn islessgreater "real-floating x" "real-floating y"
+.Ft int
+.Fn isunordered "real-floating x" "real-floating y"
+.Sh DESCRIPTION
+Each of the macros
+.Fn isgreater ,
+.Fn isgreaterequal ,
+.Fn isless ,
+.Fn islessequal ,
+and
+.Fn islessgreater
+take arguments
+.Va x
+and
+.Va y
+and return a non-zero value if and only if its nominal
+relation on
+.Va x
+and
+.Va y
+is true.
+These macros always return zero if either
+argument is a not a number (NaN), but unlike the corresponding C
+operators, they never raise a floating point exception.
+.Pp
+The
+.Fn isunordered
+macro takes arguments
+.Va x
+and
+.Va y
+and returns non-zero if and only if neither
+.Va x
+nor
+.Va y
+are NaNs.
+For any pair of floating-point values, one
+of the relationships (less, greater, equal, unordered) holds.
+.Sh SEE ALSO
+.Xr fpclassify 3 ,
+.Xr math 3 ,
+.Xr signbit 3
+.Sh STANDARDS
+The
+.Fn isgreater ,
+.Fn isgreaterequal ,
+.Fn isless ,
+.Fn islessequal ,
+.Fn islessgreater ,
+and
+.Fn isunordered
+macros conform to
+.St -isoC-99 .
+.Sh HISTORY
+The relational macros described above first appeared in
+.Fx 5.1 .
diff --git a/lib/libc/gen/isinf.3 b/lib/libc/gen/isinf.3
deleted file mode 100644
index 3fdc582..0000000
--- a/lib/libc/gen/isinf.3
+++ /dev/null
@@ -1,80 +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.
-.\"
-.\" @(#)isinf.3 8.2 (Berkeley) 1/29/94
-.\" $FreeBSD$
-.\"
-.Dd January 29, 1994
-.Dt ISINF 3
-.Os
-.Sh NAME
-.Nm isinf ,
-.Nm isnan ,
-.Nm isnanf
-.Nd test for infinity or not-a-number
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.Ft int
-.Fn isinf double
-.Ft int
-.Fn isnan double
-.Ft int
-.Fn isnanf float
-.Sh DESCRIPTION
-The
-.Fn isinf
-function
-returns 1 if the number is
-.Dq \\*(If ,
-otherwise 0.
-.Pp
-The
-.Fn isnan
-and
-.Fn isnanf
-functions
-return 1 if the double or float (respectively) is
-.Dq not-a-number ,
-otherwise 0.
-.Sh SEE ALSO
-.Xr math 3
-.Rs
-.%T "IEEE Standard for Binary Floating-Point Arithmetic"
-.%Q ANSI
-.%R Std 754-1985
-.Re
-.Sh BUGS
-Neither the
-.Tn VAX
-nor the Tahoe floating point have distinguished values
-for either infinity or not-a-number.
-These routines always return 0 on those architectures.
diff --git a/lib/libc/i386/gen/isinf.c b/lib/libc/i386/gen/isinf.c
index e735cd4..d894b4f 100644
--- a/lib/libc/i386/gen/isinf.c
+++ b/lib/libc/i386/gen/isinf.c
@@ -31,6 +31,8 @@
* 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 */
diff --git a/lib/libc/ia64/gen/isinf.c b/lib/libc/ia64/gen/isinf.c
index d878905..f47ef61 100644
--- a/lib/libc/ia64/gen/isinf.c
+++ b/lib/libc/ia64/gen/isinf.c
@@ -27,6 +27,8 @@
* rights to redistribute these changes.
*/
+/* For binary compat; to be removed in FreeBSD 6.0. */
+
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
@@ -34,6 +36,9 @@ __FBSDID("$FreeBSD$");
#include <machine/ieee.h>
#include <math.h>
+#undef isnan
+#undef isinf
+
int
isnan(d)
double d;
diff --git a/lib/libc/powerpc/gen/isinf.c b/lib/libc/powerpc/gen/isinf.c
index b162817..fb6d73b 100644
--- a/lib/libc/powerpc/gen/isinf.c
+++ b/lib/libc/powerpc/gen/isinf.c
@@ -28,6 +28,8 @@
* 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$");
@@ -35,6 +37,9 @@ __FBSDID("$FreeBSD$");
#include <machine/ieee.h>
#include <math.h>
+#undef isnan
+#undef isinf
+
int
isnan(double d)
{
diff --git a/lib/libc/sparc64/gen/isinf.c b/lib/libc/sparc64/gen/isinf.c
index 996ad12..c92650e 100644
--- a/lib/libc/sparc64/gen/isinf.c
+++ b/lib/libc/sparc64/gen/isinf.c
@@ -28,6 +28,8 @@
* 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$");
@@ -35,6 +37,9 @@ __FBSDID("$FreeBSD$");
#include <machine/ieee.h>
#include <math.h>
+#undef isnan
+#undef isinf
+
int
isnan(d)
double d;
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