Split out from ieee(3) also the remainder(3) and copysign(3) families.

This commit is contained in:
jruoho 2011-04-13 04:57:10 +00:00
parent 1ed2588de8
commit 9d56ec39d7
4 changed files with 255 additions and 88 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.105 2011/04/12 07:29:50 jruoho Exp $
# $NetBSD: Makefile,v 1.106 2011/04/13 04:57:11 jruoho Exp $
#
# @(#)Makefile 5.1beta 93/09/24
#
@ -200,11 +200,15 @@ SRCS:=${SRCS} n_sqrt.S n_argred.S n_infnan.S n_atan2.S n_cabs.S n_cbrt.S \
COPTS.s_tanh.c+= -O0
.endif
MAN+= acos.3 acosh.3 asin.3 asinh.3 atan.3 atan2.3 atanh.3 ceil.3 \
cos.3 cosh.3 erf.3 exp.3 fabs.3 floor.3 fmod.3 frexp.3 hypot.3 ieee.3 \
MAN+= acos.3 acosh.3 asin.3 asinh.3 atan.3 atan2.3 atanh.3 \
ceil.3 copysign.3 cos.3 cosh.3 \
erf.3 exp.3 \
fabs.3 floor.3 fmod.3 frexp.3 hypot.3 ieee.3 \
ieee_test.3 isinff.3 j0.3 ldexp.3 lgamma.3 lrint.3 \
math.3 modf.3 nextafter.3 rint.3 round.3 sin.3 sinh.3 \
sqrt.3 tan.3 tanh.3 trunc.3 fmax.3 fdim.3
math.3 modf.3 nextafter.3 \
remainder.3 rint.3 round.3 \
sin.3 sinh.3 sqrt.3 \
tan.3 tanh.3 trunc.3 fmax.3 fdim.3
# fenv.h interface
MAN+= feclearexcept.3 feenableexcept.3 fegetenv.3 fegetround.3 fenv.3
@ -227,6 +231,8 @@ MLINKS+=atan.3 atanf.3
MLINKS+=atan2.3 atan2f.3
MLINKS+=atanh.3 atanhf.3
MLINKS+=ceil.3 ceilf.3
MLINKS+=copysign.3 copysignf.3 \
copysign.3 copysignl.3
MLINKS+=cos.3 cosf.3
MLINKS+=cosh.3 coshf.3
MLINKS+=erf.3 erff.3 erf.3 erfc.3 erf.3 erfcf.3
@ -241,11 +247,8 @@ MLINKS+=fabs.3 fabsf.3
MLINKS+=floor.3 floorf.3
MLINKS+=fmod.3 fmodf.3
MLINKS+=hypot.3 hypotf.3
MLINKS+=ieee.3 copysign.3 ieee.3 copysignf.3 ieee.3 copysignl.3 \
ieee.3 finite.3 ieee.3 finitef.3 \
MLINKS+=ieee.3 finite.3 ieee.3 finitef.3 \
ieee.3 ilogb.3 ieee.3 ilogbf.3 \
ieee.3 remainder.3 ieee.3 remainderf.3 \
ieee.3 remquo.3 ieee.3 remquof.3 \
ieee.3 scalbn.3 ieee.3 scalbnf.3
MLINKS+=ieee_test.3 logb.3 ieee_test.3 logbf.3
MLINKS+=ieee_test.3 scalb.3 ieee_test.3 scalbf.3
@ -260,6 +263,9 @@ MLINKS+=nextafter.3 nextafterf.3 \
nextafter.3 nextafterl.3 \
nextafter.3 nexttoward.3
MLINKS+=lrint.3 lrintf.3 lrint.3 llrint.3 lrint.3 llrintf.3
MLINKS+=remainder.3 remainderf.3 \
remainder.3 remquo.3 \
remainder.3 remquof.3
MLINKS+=rint.3 rintf.3
MLINKS+=sin.3 sinf.3
MLINKS+=sinf.3 sinhf.3

90
lib/libm/man/copysign.3 Normal file
View File

@ -0,0 +1,90 @@
.\" $NetBSD: copysign.3,v 1.1 2011/04/13 04:57:10 jruoho Exp $
.\"
.\" Copyright (c) 2011 Jukka Ruohonen <jruohonen@iki.fi>
.\" 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
.\"
.Dd April 13, 2011
.Dt COPYSIGN 3
.Os
.Sh NAME
.Nm copysign ,
.Nm copysignf ,
.Nm copysignl
.Nd functions to manipulate signs
.Sh LIBRARY
.Lb libm
.Sh SYNOPSIS
.In math.h
.Ft double
.Fn copysign "double x" "double y"
.Ft float
.Fn copysignf "float x" "float y"
.Ft long double
.Fn copysignl "long double x" "long double y"
.Sh DESCRIPTION
The
.Fn copysign ,
.Fn copysignf ,
and
.Fn copysignl
functions return a value whose absolute value matches
.Fa x ,
but whose sign bit is taken from
.Fa y .
.Sh RETURN VALUES
Upon successful completion,
all three functions return a value with the magnitude of
.Fa x
and the sign of
.Fa y .
If
.Fa x
is
\*(Na ,
the functions return a
\*(Na
with the sign of
.Fa y .
.Sh SEE ALSO
.Xr math 3 ,
.Xr signbit 3
.Sh STANDARDS
The described functions conform to
.St -isoC-99 .
.\"
.\" XXX: Verify this.
.\"
.\" The functions are also recommended by
.\" .St -ieee754
.\"
.\" .Sh HISTORY
.\"
.\" XXX: Fill this.
.\"
.\" These functions first appeared in ???.
.\"
.Sh CAVEATS
Note that on implementations that represent a signed zero
but do not treat negative zero consistently in arithmetic operations,
these functions may regard the sign of zero as positive.

View File

@ -26,21 +26,16 @@
.\" SUCH DAMAGE.
.\"
.\" from: @(#)ieee.3 6.4 (Berkeley) 5/6/91
.\" $NetBSD: ieee.3,v 1.23 2011/04/12 07:29:50 jruoho Exp $
.\" $NetBSD: ieee.3,v 1.24 2011/04/13 04:57:10 jruoho Exp $
.\"
.Dd April 12, 2011
.Dt IEEE 3
.Os
.Sh NAME
.Nm copysign ,
.Nm copysignf ,
.Nm copysignl ,
.Nm finite ,
.Nm finitef ,
.Nm ilogb ,
.Nm ilogbf ,
.Nm remainder ,
.Nm remainderf ,
.Nm scalbn ,
.Nm scalbnf
.Nd functions for IEEE arithmetic
@ -48,12 +43,6 @@
.Lb libm
.Sh SYNOPSIS
.In math.h
.Ft double
.Fn copysign "double x" "double y"
.Ft float
.Fn copysignf "float x" "float y"
.Ft long double
.Fn copysignl "long double x" "long double y"
.Ft int
.Fn finite "double x"
.Ft int
@ -63,14 +52,6 @@
.Ft int
.Fn ilogbf "float x"
.Ft double
.Fn remainder "double x" "double y"
.Ft float
.Fn remainderf "float x" "float y"
.Ft double
.Fn remquo "double x" "double y" "int *quo"
.Ft float
.Fn remquof "float x" "float y" "int *quo"
.Ft double
.Fn scalbn "double x" "int n"
.Ft float
.Fn scalbnf "float x" "int n"
@ -78,12 +59,6 @@
These functions are required or recommended by
.St -ieee754 .
.Pp
.Fn copysign
returns
.Fa x
with its sign changed to
.Fa y Ns 's .
.Pp
.Fn finite
returns the value 1 just when
\-\*(If \*(Lt
@ -109,60 +84,7 @@ and
.Fn ilogb 0
returns
.Dv INT_MIN .
.Pp
.Fn remainder
returns the remainder
.Fa r
:=
.Fa x
\-
.Fa n\(**y
where
.Fa n
is the integer nearest the exact value of
.Bk -words
.Fa x Ns / Ns Fa y ;
.Ek
moreover if
.Pf \*(Ba Fa n
\-
.Sm off
.Fa x No / Fa y No \*(Ba
.Sm on
=
1/2
then
.Fa n
is even.
Consequently the remainder is computed exactly and
.Sm off
.Pf \*(Ba Fa r No \*(Ba
.Sm on
\*(Le
.Sm off
.Pf \*(Ba Fa y No \*(Ba/2 .
.Sm on
But
.Fn remainder x 0
and
.Fn remainder \*(If 0
are invalid operations that produce a \*(Na.
.Pp
.Fn remquo
is the same as
.Fn remainder
but also stores the last
.Va k
bits of
.Fa n
in the location pointed to by
.Fa quo ,
provided that
.Fa n
exists.
The number of bits
.Va k
is platform-specific, but is guaranteed to be at least 3.
.Pp
.Fn scalbn
returns

149
lib/libm/man/remainder.3 Normal file
View File

@ -0,0 +1,149 @@
.\" $NetBSD: remainder.3,v 1.1 2011/04/13 04:57:10 jruoho Exp $
.\"
.\" Copyright (c) 2011 Jukka Ruohonen <jruohonen@iki.fi>
.\" 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
.\"
.Dd April 13, 2011
.Dt REMAINDER 3
.Os
.Sh NAME
.Nm remainder ,
.Nm remainderf ,
.Nm remquo ,
.Nm remquof
.Nd remainder functions
.Sh LIBRARY
.Lb libm
.Sh SYNOPSIS
.In math.h
.Ft double
.Fn remainder "double x" "double y"
.Ft float
.Fn remainderf "float x" "float y"
.Ft double
.Fn remquo "double x" "double y" "int *quo"
.Ft float
.Fn remquof "float x" "float y" "int *quo"
.Sh DESCRIPTION
Provided that
.Fa y
\*(Ne 0 ,
the
.Fn remainder
and
.Fn remainderf
functions calculate the floating-point remainder
.Fa r
of
.Bd -ragged -offset indent
.Va r
=
.Va x - ny ,
.Ed
.Pp
where
.Fa n
is the integral value nearest to the exact value of
.Fa x
/
.Fa y .
If
.Bd -ragged -offset indent
.Va | n
-
.Va x / y |
= 1/2 ,
.Ed
.Pp
the value
.Fa n
is chosen to be even.
Consequently, the remainder is computed exactly and
.Va | r |
\*(Le
.Fa | y |
/ 2 .
.Pp
Also the
.Fn remquo
and
.Fn remquof
functions calculate the remainder as described above.
But these additionally use
.Fa quo
to store a value whose sign is the sign of
.Va x / y
and whose magnitude is congruent modulo
.Va 2^k
to the magnitude of the integral quotient of
.Va x / y ,
where
.Fa k
is an implementation-defined integer greater than or equal to 3.
.Pp
The rationale of the
.Fn remquo
family of functions relates to situations where
only few bits of the quotient are required.
The exact representation of the quotient may not be meaningful when
.Fa x
is large in magnitude compared to
.Fa y .
.Sh RETURN VALUES
The functions return the remainder independent of the rounding mode.
If
.Fa y
is zero ,
\*(Na
is returned and a domain error occurs.
A domain error occurs and a
\*(Na
is returned also when
.Fa x
is infinite but
.Fa y
is not a
\*(Na.
If either
.Fa x
or
.Fa y
is
\*(Na,
a
\*(Na
is always returned.
.Sh SEE ALSO
.Xr div 3 ,
.Xr fast_remainder32 3 ,
.Xr fmod 3 ,
.Xr math 3
.Sh STANDARDS
The described functions conform to
.St -isoC-99 .
.Sh BUGS
The
.Vt long double
variants are not yet supported in
.Nx .