diff options
author | mike <mike@FreeBSD.org> | 2003-02-11 21:56:21 +0000 |
---|---|---|
committer | mike <mike@FreeBSD.org> | 2003-02-11 21:56:21 +0000 |
commit | b56a102d98cd205397bde43f1b2a9ac119f0028d (patch) | |
tree | b8970625bfd29f2ebf574f2547dab4599320a895 /lib | |
parent | b65dfed25b7d235dd26e37e6b7cf060f70360438 (diff) | |
download | FreeBSD-src-b56a102d98cd205397bde43f1b2a9ac119f0028d.zip FreeBSD-src-b56a102d98cd205397bde43f1b2a9ac119f0028d.tar.gz |
Implement C99's signbit() macro.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/gen/Makefile.inc | 5 | ||||
-rw-r--r-- | lib/libc/gen/signbit.3 | 57 | ||||
-rw-r--r-- | lib/libc/gen/signbit.c | 40 | ||||
-rw-r--r-- | lib/msun/src/math.h | 2 |
4 files changed, 102 insertions, 2 deletions
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc index 93be60b..c6ad6f2 100644 --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -24,7 +24,7 @@ SRCS+= __xuname.c _pthread_stubs.c _rand48.c _spinlock_stub.c _thread_init.c \ scandir.c seed48.c seekdir.c semctl.c \ setdomainname.c sethostname.c setjmperr.c setmode.c \ setproctitle.c setprogname.c \ - siginterrupt.c siglist.c signal.c \ + siginterrupt.c siglist.c signal.c signbit.c \ sigsetops.c sleep.c srand48.c statvfs.c stringlist.c strtofflags.c \ sysconf.c sysctl.c sysctlbyname.c sysctlnametomib.c \ syslog.c telldir.c termios.c time.c times.c timezone.c ttyname.c \ @@ -53,7 +53,8 @@ MAN+= alarm.3 arc4random.3 \ nice.3 nlist.3 pause.3 popen.3 pselect.3 psignal.3 pwcache.3 \ raise.3 rand48.3 readpassphrase.3 rfork_thread.3 \ scandir.3 setjmp.3 setmode.3 setproctitle.3 shm_open.3 \ - siginterrupt.3 signal.3 sigsetops.3 sleep.3 statvfs.3 stringlist.3 \ + siginterrupt.3 signal.3 signbit.3 sigsetops.3 sleep.3 \ + statvfs.3 stringlist.3 \ strtofflags.3 sysconf.3 sysctl.3 syslog.3 tcgetpgrp.3 \ tcsendbreak.3 tcsetattr.3 tcsetpgrp.3 time.3 times.3 timezone.3 \ ttyname.3 tzset.3 ualarm.3 ucontext.3 ulimit.3 uname.3 \ diff --git a/lib/libc/gen/signbit.3 b/lib/libc/gen/signbit.3 new file mode 100644 index 0000000..b8d4bb7 --- /dev/null +++ b/lib/libc/gen/signbit.3 @@ -0,0 +1,57 @@ +.\" Copyright (c) 2003 Mike Barcroft <mike@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$ +.\" +.Dd February 11, 2003 +.Dt FPCLASSIFY 3 +.Os +.Sh NAME +.Nm signbit +.Nd "determine whether a floating-point number's sign is negative" +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In math.h +.Ft int +.Fn signbit "real-floating x" +.Sh DESCRIPTION +The +.Fn signbit +macro takes an argument of +.Va x +and returns non-zero if the value of its sign is negative, otherwise 0. +.Sh SEE ALSO +.Xr fpclassify 3 , +.Xr math 3 +.Sh STANDARDS +The +.Fn signbit +macro conforms to +.St -isoC-99 . +.Sh HISTORY +The +.Fn signbit +macro was added in +.Fx 5.1 . diff --git a/lib/libc/gen/signbit.c b/lib/libc/gen/signbit.c new file mode 100644 index 0000000..02b48ee --- /dev/null +++ b/lib/libc/gen/signbit.c @@ -0,0 +1,40 @@ +/*- + * Copyright (c) 2003 Mike Barcroft <mike@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 +__signbit(double d) +{ + union IEEEd2bits u; + + u.d = d; + return (u.bits.sign); +} diff --git a/lib/msun/src/math.h b/lib/msun/src/math.h index abeca6e..b902df1 100644 --- a/lib/msun/src/math.h +++ b/lib/msun/src/math.h @@ -50,6 +50,7 @@ extern const union __nan_un { ((sizeof (x) == sizeof (float)) ? __fpclassifyf(x) \ : (sizeof (x) == sizeof (double)) ? __fpclassifyd(x) \ : __fpclassifyl(x)) +#define signbit(x) __signbit(x) typedef __double_t double_t; typedef __float_t float_t; @@ -147,6 +148,7 @@ __BEGIN_DECLS int __fpclassifyd(double); int __fpclassifyf(float); int __fpclassifyl(long double); +int __signbit(double); double acos(double); double asin(double); |