Implement C99's signbit() macro.

This commit is contained in:
Mike Barcroft 2003-02-11 21:56:21 +00:00
parent ee7785a7f8
commit 8e9b28311e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=110734
4 changed files with 102 additions and 2 deletions

View file

@ -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 \ scandir.c seed48.c seekdir.c semctl.c \
setdomainname.c sethostname.c setjmperr.c setmode.c \ setdomainname.c sethostname.c setjmperr.c setmode.c \
setproctitle.c setprogname.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 \ sigsetops.c sleep.c srand48.c statvfs.c stringlist.c strtofflags.c \
sysconf.c sysctl.c sysctlbyname.c sysctlnametomib.c \ sysconf.c sysctl.c sysctlbyname.c sysctlnametomib.c \
syslog.c telldir.c termios.c time.c times.c timezone.c ttyname.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 \ nice.3 nlist.3 pause.3 popen.3 pselect.3 psignal.3 pwcache.3 \
raise.3 rand48.3 readpassphrase.3 rfork_thread.3 \ raise.3 rand48.3 readpassphrase.3 rfork_thread.3 \
scandir.3 setjmp.3 setmode.3 setproctitle.3 shm_open.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 \ strtofflags.3 sysconf.3 sysctl.3 syslog.3 tcgetpgrp.3 \
tcsendbreak.3 tcsetattr.3 tcsetpgrp.3 time.3 times.3 timezone.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 \ ttyname.3 tzset.3 ualarm.3 ucontext.3 ulimit.3 uname.3 \

57
lib/libc/gen/signbit.3 Normal file
View file

@ -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 .

40
lib/libc/gen/signbit.c Normal file
View file

@ -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);
}

View file

@ -50,6 +50,7 @@ extern const union __nan_un {
((sizeof (x) == sizeof (float)) ? __fpclassifyf(x) \ ((sizeof (x) == sizeof (float)) ? __fpclassifyf(x) \
: (sizeof (x) == sizeof (double)) ? __fpclassifyd(x) \ : (sizeof (x) == sizeof (double)) ? __fpclassifyd(x) \
: __fpclassifyl(x)) : __fpclassifyl(x))
#define signbit(x) __signbit(x)
typedef __double_t double_t; typedef __double_t double_t;
typedef __float_t float_t; typedef __float_t float_t;
@ -147,6 +148,7 @@ __BEGIN_DECLS
int __fpclassifyd(double); int __fpclassifyd(double);
int __fpclassifyf(float); int __fpclassifyf(float);
int __fpclassifyl(long double); int __fpclassifyl(long double);
int __signbit(double);
double acos(double); double acos(double);
double asin(double); double asin(double);