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>
This commit is contained in:
parent
cc8557f550
commit
5d62092f94
@ -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;
|
||||
|
@ -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 */
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
102
lib/libc/gen/isgreater.3
Normal file
102
lib/libc/gen/isgreater.3
Normal file
@ -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 .
|
@ -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.
|
@ -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 */
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user