xref: /csrg-svn/lib/libm/common_source/ieee.3 (revision 61304)
1*61304Sbostic.\" Copyright (c) 1985, 1991, 1993
2*61304Sbostic.\"	The Regents of the University of California.  All rights reserved.
324695Smckusick.\"
449229Scael.\" %sccs.include.redist.roff%
524695Smckusick.\"
6*61304Sbostic.\"     @(#)ieee.3	8.1 (Berkeley) 06/04/93
748352Scael.\"
848352Scael.Dd
948352Scael.Dt IEEE 3
1048352Scael.Os BSD 4.3
1148352Scael.Sh NAME
1248352Scael.Nm copysign ,
1348352Scael.Nm drem ,
1448352Scael.Nm finite ,
1548352Scael.Nm logb ,
1648352Scael.Nm scalb
1758395Sbostic.Nd "IEEE 754 floating point support
1848352Scael.Sh SYNOPSIS
1948352Scael.Fd #include <math.h>
2048352Scael.Ft double
2148352Scael.Fn copysign "double x" "double y"
2248352Scael.Ft double
2348352Scael.Fn drem "double x" "double y"
2448352Scael.Ft int
2548352Scael.Fn finite "double x"
2648352Scael.Ft double
2748352Scael.Fn logb "double x"
2848352Scael.Ft double
2948352Scael.Fn scalb "double x" "int n"
3048352Scael.Sh DESCRIPTION
3148352ScaelThese functions are required for, or recommended by the
3248352Scael.Tn IEEE
3348352Scaelstandard
3424373Smiriam754 for floating\-point arithmetic.
3548352Scael.Pp
3648352ScaelThe
3748352Scael.Fn copysign
3848352Scaelfunction
3948352Scaelreturns
4048352Scael.Fa x
4148352Scaelwith its sign changed to
4248352Scael.Fa y Ns 's.
4348352Scael.Pp
4448352ScaelThe
4548352Scael.Fn drem
4648352Scaelfunction
4748352Scaelreturns the remainder
4848352Scael.Fa r
4948352Scael:=
5048352Scael.Fa x
5148352Scael\-
5248352Scael.Fa n\(**y
5348352Scaelwhere
5448352Scael.Fa n
5548352Scaelis the integer nearest the exact value of
5648352Scael.Bk -words
5748352Scael.Fa x Ns / Ns Fa y ;
5848352Scael.Ek
5948352Scaelmoreover if
6048352Scael.Pf \\*(Ba Fa n
6148352Scael\-
6248352Scael.Sm off
6348352Scael.Fa x No / Fa y No \\*(Ba
6448352Scael.Sm on
6548352Scael=
6648352Scael1/2
6748352Scaelthen
6848352Scael.Fa n
6948352Scaelis even.  Consequently
7048352Scaelthe remainder is computed exactly and
7148352Scael.Sm off
7248352Scael.Pf \\*(Ba Fa r No \\*(Ba
7348352Scael.Sm on
7448352Scael\*(Le
7548352Scael.Sm off
7648352Scael.Pf \\*(Ba Fa y No \\*(Ba/2.
7748352Scael.Sm on
7848352ScaelBut
7948352Scael.Fn drem x 0
8048352Scaelis exceptional.
8148352Scael(See below under
8248352Scael.Sx DIAGNOSTICS . )
8348352Scael.Pp
8448352ScaelThe
8548352Scael.Fn finite
8648352Scaelfunction returns the value 1 just when
8748352Scael\-\*(If \*(Lt
8848352Scael.Fa x
8948352Scael\*(Lt +\*(If;
9048352Scaelotherwise a
9148352Scaelzero is returned
9248352Scael(when
9348352Scael.Pf \\*(Ba Ns Fa x Ns \\*(Ba
9448352Scael= \*(If or
9548352Scael.Fa x
9648352Scaelis \*(Na or
9748352Scaelis the
9848352Scael.Tn VAX Ns 's
9948352Scaelreserved operand).
10048352Scael.Pp
10148352ScaelThe
10248352Scael.Fn logb
10348352Scaelfunction returns
10448352Scael.Fa x Ns 's exponent
10548352Scael.Fa n ,
10624373Smiriama signed integer converted to double\-precision floating\-point and so
10748352Scaelchosen that
10848352Scael1 (<=
10948352Scael.Pf \\*(Ba Ns Fa x Ns \\*(Ba2** Ns Fa n
11048352Scael< 2
11148352Scaelunless
11248352Scael.Fa x
11348352Scael= 0 or
11448352Scael(only on machines that conform to
11548352Scael.Tn IEEE
11648352Scael754)
11748352Scael.Pf \\*(Ba Fa x Ns \\*(Ba
11848352Scael= \*(If
11948352Scaelor
12048352Scael.Fa x
12148352Scaellies between 0 and the Underflow Threshold.
12248352Scael(See below under
12348352Scael.Sx BUGS . )
12448352Scael.Pp
12548352ScaelThe
12658395Sbostic.Fn scalb
12758395Sbosticfunction returns
12848352Scael.Fa x Ns \(**(2** Ns Fa n )
12948352Scaelcomputed, for integer n, without first computing
13048352Scael.Pf 2\(** Fa n .
13148352Scael.Sh RETURN VALUES
13248352ScaelThe
13348352Scael.Tn IEEE
13448352Scaelstandard
13548352Scael754 defines
13648352Scael.Fn drem x 0
13748352Scaeland
13848352Scael.Fn drem \\*(If y
13948352Scaelto be invalid operations that produce a \*(Na.
14048352ScaelOn the
14148352Scael.Tn VAX ,
14248352Scael.Fn drem x 0
14348352Scaelgenerates a reserved operand fault.  No \*(If
14448352Scaelexists on a
14548352Scael.Tn VAX .
14648352Scael.Pp
14748352Scael.Tn IEEE
14848352Scael754 defines
14921079Smiriam.if n \
15048352Scael.Fn logb \(+-\\*(If
15148352Scael= \*(If and
15248352Scael.Fn logb 0
15348352Scael= \-\*(If, and
15424373Smiriamrequires the latter to signal Division\-by\-Zero.
15548352ScaelBut on a
15648352Scael.Tn VAX ,
15748352Scael.Fn logb 0
15848352Scael= 1.0 \- 2.0**31 = \-2,147,483,647.0.
15948352ScaelAnd if the correct value of
16048352Scael.Fn scalb
16148352Scaelwould overflow on a
16248352Scael.Tn VAX ,
16348352Scaelit generates a reserved operand fault and sets the global variable
16448352Scael.Va errno
16548352Scaelto
16648352Scael.Dv ERANGE .
16748352Scael.Sh SEE ALSO
16848352Scael.Xr floor 3 ,
16948352Scael.Xr math 3 ,
17048352Scael.Xr infnan 3
17148352Scael.Sh HISTORY
17248352ScaelThe
17348352Scael.Nm ieee
17448352Scaelfunctions appeared in
17548352Scael.Bx 4.3 .
17648352Scael.Sh BUGS
17748352ScaelShould
17848352Scael.Fn drem x 0
17948352Scaeland
18048352Scael.Fn logb 0
18148352Scaelon a
18248352Scael.Tn VAX
18348352Scaelsignal invalidity
18448352Scaelby setting
18548352Scael.Va errno No = Dv EDOM ?
18648352ScaelShould
18748352Scael.Fn logb 0
18848352Scaelreturn  \-1.7e38?
18948352Scael.Pp
19048352Scael.Tn IEEE
19148352Scael754 currently specifies that
19248352Scael.Fn logb "denormalized no."
19348352Scael=
19448352Scael.Fn logb "tiniest normalized no. > 0"
19524373Smiriambut the consensus has changed to the specification in the new
19648352Scaelproposed
19748352Scael.Tn IEEE
19848352Scaelstandard p854, namely that
19948352Scael.Fn logb x
20048352Scaelsatisfy
20148352Scael.Bd -filled -offset indent
20248352Scael1 \(<=
20348352Scael.Fn scalb \\*(Bax\\*(Ba \-logb(x)
20448352Scael<
20548352ScaelRadix\0 ... = 2
20648352Scaelfor
20748352Scael.Tn IEEE
20848352Scael754
20948352Scael.Ed
21048352Scael.Pp
21124373Smiriamfor every x except 0,
21248352Scael\*(If
21348352Scaeland \*(Na.
21424373SmiriamAlmost every program that assumes 754's specification will work
21548352Scaelcorrectly if
21648352Scael.Fn logb
21748352Scaelfollows 854's specification instead.
21848352Scael.Pp
21948352Scael.Tn IEEE
22048352Scael754 requires
22148352Scael.Fn copysign x \\*(Na)
22248352Scael=
22348352Scael.Pf \(+- Ns Fa x
22448352Scaelbut says nothing
22548352Scaelelse about the sign of a \*(Na.  A \*(Na
22658395Sbostic.Em (N Ns ot
22748352Scael.Em a
22848352Scael.Em N Ns umber )
22948352Scaelis
23048352Scaelsimilar in spirit to the
23148352Scael.Tn VAX Ns 's
23248352Scaelreserved operand, but very
23324373Smiriamdifferent in important details.  Since the sign bit of a
23424373Smiriamreserved operand makes it look negative,
23548352Scael.Bd -filled -offset indent
23648352Scael.Fn copysign x "reserved operand"
23748352Scael=
23848352Scael.Pf \- Fa x ;
23948352Scael.Ed
24048352Scael.Pp
24124373Smiriamshould this return the reserved operand instead?
242