Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 8 Feb 2003 13:09:25 +0100 (CET)
From:      Lukas Ertl <l.ertl@univie.ac.at>
To:        David Schultz <dschultz@uclink.Berkeley.EDU>
Cc:        standards@FreeBSD.ORG
Subject:   Re: C99 floating point macros
Message-ID:  <20030208130529.C355@leelou.in.tern>
In-Reply-To: <20030208112619.GA15718@HAL9000.homeunix.com>
References:  <20030207194848.N353@leelou.in.tern> <20030208112619.GA15718@HAL9000.homeunix.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, 8 Feb 2003, David Schultz wrote:

> Thus spake Lukas Ertl <l.ertl@univie.ac.at>:
> > I hope I don't sound too stupid but I'd like to contribute something to
> > FreeBSD. Looking through the C99 status board I found noone has started
> > working on implementation of the C99 macros isgreater, isless etc. If I
> > read the standard correctly it doesn't seem to be so hard to implement
> > them, but I'm having some questions:
> >
> > *) Where should I put additional source files / change existing ones to
> >    confirm to the FreeBSD source tree?
>
> If your changes are MI macros, then they go in math.h.  Otherwise,
> look at the forthcoming machine/_math.h.

Ok, please review the following patch. I hope I didn't take it too easy.
:-)

--8<--
Index: lib/libc/gen/Makefile.inc
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /u/cvs/cvs/src/lib/libc/gen/Makefile.inc,v
retrieving revision 1.100
diff -u -r1.100 Makefile.inc
--- lib/libc/gen/Makefile.inc=0930 Jan 2003 21:38:39 -0000=091.100
+++ lib/libc/gen/Makefile.inc=098 Feb 2003 12:03:44 -0000
@@ -16,7 +16,7 @@
 =09getobjformat.c getosreldate.c getpagesize.c \
 =09getpeereid.c getprogname.c getpwent.c getttyent.c \
 =09getusershell.c getvfsbyname.c getvfsent.c glob.c \
-=09initgroups.c isatty.c jrand48.c lcong48.c \
+=09initgroups.c isatty.c isgreater.c jrand48.c lcong48.c \
 =09lockf.c lrand48.c mrand48.c nice.c \
 =09nlist.c nrand48.c ntp_gettime.c opendir.c \
 =09pause.c popen.c posixshm.c pselect.c psignal.c pw_scan.c pwcache.c \
@@ -47,7 +47,7 @@
 =09getmntinfo.3 getnetgrent.3 getobjformat.3 getosreldate.3 \
 =09getpagesize.3 getpass.3 getpeereid.3 getprogname.3 getpwent.3 \
 =09getttyent.3 getusershell.3 getvfsbyname.3 getvfsent.3 \
-=09glob.3 initgroups.3 isinf.3 ldexp.3 lockf.3 makecontext.3 \
+=09glob.3 initgroups.3 isgreater.3 isinf.3 ldexp.3 lockf.3 makecontext.3 \
 =09modf.3 msgctl.3 msgget.3 msgrcv.3 msgsnd.3 \
 =09nice.3 nlist.3 pause.3 popen.3 pselect.3 psignal.3 pwcache.3 \
 =09raise.3 rand48.3 readpassphrase.3 rfork_thread.3 \
@@ -97,6 +97,9 @@
 =09getvfsent.3 setvfsent.3 getvfsent.3 vfsisloadable.3 \
 =09getvfsent.3 vfsload.3
 MLINKS+=3Dglob.3 globfree.3
+MLINKS+=3Disgreater.3 isgreaterequal.3 isgreater.3 isless.3 \
+=09=09isgreater.3 islessequal.3 isgreater.3 islessgreater.3 \
+=09=09isgreater.3 isunordered.3
 MLINKS+=3Disinf.3 isnan.3 isinf.3 isnanf.3
 MLINKS+=3Dmakecontext.3 swapcontext.3
 MLINKS+=3Dpopen.3 pclose.3
Index: lib/libc/gen/isgreater.3
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: lib/libc/gen/isgreater.3
diff -N lib/libc/gen/isgreater.3
--- /dev/null=091 Jan 1970 00:00:00 -0000
+++ lib/libc/gen/isgreater.3=098 Feb 2003 12:03:44 -0000
@@ -0,0 +1,121 @@
+.\" Copyright (c) 2003 Lukas Ertl <l.ertl@univie.ac.at>
+.\" 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=
=2E
+.\"
+.\" 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 PUR=
POSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABL=
E
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUEN=
TIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOOD=
S
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, ST=
RICT
+.\" 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 8, 2003
+.Dt ISGREATER 3
+.Os
+.Sh NAME
+.Nm isgreater ,
+.Nm isgreaterequal ,
+.Nm isless ,
+.Nm islessequal ,
+.Nm islessgreater ,
+.Nm isunordered
+.Nd "test if x is less or greater than y"
+.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
+The
+.Fn isgreater
+macro returns 1 if argument
+.Va x
+is greater than argument
+.Va y ,
+or 0 otherwise.
+.Pp
+The
+.Fn isgreaterequal
+macro returns 1 if argument
+.Va x
+is greater than or equal to argument
+.Va y ,
+or 0 otherwise.
+.Pp
+The
+.Fn isless
+macro returns 1 if argument
+.Va x
+is less than argument
+.Va y ,
+or 0 otherwise.
+.Pp
+The
+.Fn islessequal
+macro returns 1 if argument
+.Va x
+is less than or equal to argument
+.Va y ,
+or 0 otherwise.
+.Pp
+The
+.Fn islessgreater
+macro returns 1 if argument
+.Va x
+is less than or greater than argument
+.Va y ,
+or 0 otherwise.
+.Pp
+The
+.Fn isunordered
+macro returns 1 its arguments are unordered or 0 otherwise.
+.Sh SEE ALSO
+.Xr math 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
+.Fn isgreater ,
+.Fn isgreaterequal ,
+.Fn isless ,
+.Fn islessequal ,
+.Fn islessgreater
+and
+.Fn isunordered
+macros were added in
+.Fx 5.1 .
Index: lib/libc/gen/isgreater.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: lib/libc/gen/isgreater.c
diff -N lib/libc/gen/isgreater.c
--- /dev/null=091 Jan 1970 00:00:00 -0000
+++ lib/libc/gen/isgreater.c=098 Feb 2003 12:03:44 -0000
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2003 Lukas Ertl <l.ertl@univie.ac.at>
+ * 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 PURP=
OSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENT=
IAL
+ * 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, STR=
ICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY W=
AY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <math.h>
+
+int
+_isgreater(double x, double y)
+{
+    if (isnan(x) || isnan(y))
+        return 0;
+
+    return (x > y);
+}
+
+int
+_isgreaterequal(double x, double y)
+{
+    if (isnan(x) || isnan(y))
+        return 0;
+
+    return (x >=3D y);
+}
+
+int
+_isless(double x, double y)
+{
+    if (isnan(x) || isnan(y))
+        return 0;
+
+    return (x < y);
+}
+
+int
+_islessequal(double x, double y)
+{
+    if (isnan(x) || isnan(y))
+        return 0;
+
+    return (x <=3D y);
+}
+
+int
+_islessgreater(double x, double y)
+{
+    if (isnan(x) || isnan(y))
+        return 0;
+
+    return ((x < y) || (x > y));
+}
+
+int
+_isunordered(double x, double y)
+{
+    if (isnan(x) || isnan(y))
+        return 1;
+    else
+        return 0;
+}
Index: lib/libc/gen/isinf.3
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /u/cvs/cvs/src/lib/libc/gen/isinf.3,v
retrieving revision 1.7
diff -u -r1.7 isinf.3
--- lib/libc/gen/isinf.3=0930 Oct 2000 13:23:18 -0000=091.7
+++ lib/libc/gen/isinf.3=098 Feb 2003 12:03:44 -0000
@@ -43,6 +43,7 @@
 .Sh LIBRARY
 .Lb libc
 .Sh SYNOPSIS
+.In math.h
 .Ft int
 .Fn isinf double
 .Ft int
Index: lib/msun/src/math.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /u/cvs/cvs/src/lib/msun/src/math.h,v
retrieving revision 1.20
diff -u -r1.20 math.h
--- lib/msun/src/math.h=0931 Oct 2002 23:05:20 -0000=091.20
+++ lib/msun/src/math.h=098 Feb 2003 12:03:49 -0000
@@ -27,6 +27,16 @@
 #define HUGE_VAL=09(__infinity.__ud)

 /*
+ * C99 comparison macros
+ */
+#define isgreater(x,y)      _isgreater(x,y)
+#define isgreaterequal(x,y) _isgreaterequal(x,y)
+#define isless(x,y)         _isless(x,y)
+#define islessequal(x,y)    _islessequal(x,y)
+#define islessgreater(x,y)  _islessgreater(x,y)
+#define isunordered(x,y)    _isunordered(x,y)
+
+/*
  * XOPEN/SVID
  */
 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
@@ -116,6 +126,14 @@
 /*
  * ANSI/POSIX
  */
+
+int     _isgreater(double, double);
+int     _isgreaterequal(double, double);
+int     _isless(double, double);
+int     _islessequal(double, double);
+int     _islessgreater(double, double);
+int     _isunordered(double, double);
+
 double=09acos(double);
 double=09asin(double);
 double=09atan(double);
---8<---

BTW, the SUSv3 text for isunordered() is b0rked, but that bug was already
reported.

best regards,
le

--=20
Lukas Ertl                             eMail: l.ertl@univie.ac.at
UNIX-Systemadministrator               Tel.:  (+43 1) 4277-14073
Zentraler Informatikdienst (ZID)       Fax.:  (+43 1) 4277-9140
der Universit=E4t Wien                   http://mailbox.univie.ac.at/~le/

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-standards" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030208130529.C355>