xref: /csrg-svn/lib/libm/common_source/ieee.3 (revision 48352)
1*48352Scael.\" Copyright (c) 1985, 1991 Regents of the University of California.
2*48352Scael.\" All rights reserved.
324695Smckusick.\"
4*48352Scael.\" %sccs.include.redist.man%
524695Smckusick.\"
6*48352Scael.\"     @(#)ieee.3	6.3 (Berkeley) 04/19/91
7*48352Scael.\"
8*48352Scael.Dd
9*48352Scael.Dt IEEE 3
10*48352Scael.Os BSD 4.3
11*48352Scael.Sh NAME
12*48352Scael.Nm copysign ,
13*48352Scael.Nm drem ,
14*48352Scael.Nm finite ,
15*48352Scael.Nm logb ,
16*48352Scael.Nm scalb
17*48352Scael.Nm copysign ,
18*48352Scael.Nm remainder,
19*48352Scael.Nd exponent manipulations
20*48352Scael.Sh SYNOPSIS
21*48352Scael.Fd #include <math.h>
22*48352Scael.Ft double
23*48352Scael.Fn copysign "double x" "double y"
24*48352Scael.Ft double
25*48352Scael.Fn drem "double x" "double y"
26*48352Scael.Ft int
27*48352Scael.Fn finite "double x"
28*48352Scael.Ft double
29*48352Scael.Fn logb "double x"
30*48352Scael.Ft double
31*48352Scael.Fn scalb "double x" "int n"
32*48352Scael.Sh DESCRIPTION
33*48352ScaelThese functions are required for, or recommended by the
34*48352Scael.Tn IEEE
35*48352Scaelstandard
3624373Smiriam754 for floating\-point arithmetic.
37*48352Scael.Pp
38*48352ScaelThe
39*48352Scael.Fn copysign
40*48352Scaelfunction
41*48352Scaelreturns
42*48352Scael.Fa x
43*48352Scaelwith its sign changed to
44*48352Scael.Fa y Ns 's.
45*48352Scael.Pp
46*48352ScaelThe
47*48352Scael.Fn drem
48*48352Scaelfunction
49*48352Scaelreturns the remainder
50*48352Scael.Fa r
51*48352Scael:=
52*48352Scael.Fa x
53*48352Scael\-
54*48352Scael.Fa n\(**y
55*48352Scaelwhere
56*48352Scael.Fa n
57*48352Scaelis the integer nearest the exact value of
58*48352Scael.Bk -words
59*48352Scael.Fa x Ns / Ns Fa y ;
60*48352Scael.Ek
61*48352Scaelmoreover if
62*48352Scael.Pf \\*(Ba Fa n
63*48352Scael\-
64*48352Scael.Sm off
65*48352Scael.Fa x No / Fa y No \\*(Ba
66*48352Scael.Sm on
67*48352Scael=
68*48352Scael1/2
69*48352Scaelthen
70*48352Scael.Fa n
71*48352Scaelis even.  Consequently
72*48352Scaelthe remainder is computed exactly and
73*48352Scael.Sm off
74*48352Scael.Pf \\*(Ba Fa r No \\*(Ba
75*48352Scael.Sm on
76*48352Scael\*(Le
77*48352Scael.Sm off
78*48352Scael.Pf \\*(Ba Fa y No \\*(Ba/2.
79*48352Scael.Sm on
80*48352ScaelBut
81*48352Scael.Fn drem x 0
82*48352Scaelis exceptional.
83*48352Scael(See below under
84*48352Scael.Sx DIAGNOSTICS . )
85*48352Scael.Pp
86*48352ScaelThe
87*48352Scael.Fn finite
88*48352Scaelfunction returns the value 1 just when
89*48352Scael\-\*(If \*(Lt
90*48352Scael.Fa x
91*48352Scael\*(Lt +\*(If;
92*48352Scaelotherwise a
93*48352Scaelzero is returned
94*48352Scael(when
95*48352Scael.Pf \\*(Ba Ns Fa x Ns \\*(Ba
96*48352Scael= \*(If or
97*48352Scael.Fa x
98*48352Scaelis \*(Na or
99*48352Scaelis the
100*48352Scael.Tn VAX Ns 's
101*48352Scaelreserved operand).
102*48352Scael.Pp
103*48352ScaelThe
104*48352Scael.Fn logb
105*48352Scaelfunction returns
106*48352Scael.Fa x Ns 's exponent
107*48352Scael.Fa n ,
10824373Smiriama signed integer converted to double\-precision floating\-point and so
109*48352Scaelchosen that
110*48352Scael1 (<=
111*48352Scael.Pf \\*(Ba Ns Fa x Ns \\*(Ba2** Ns Fa n
112*48352Scael< 2
113*48352Scaelunless
114*48352Scael.Fa x
115*48352Scael= 0 or
116*48352Scael(only on machines that conform to
117*48352Scael.Tn IEEE
118*48352Scael754)
119*48352Scael.Pf \\*(Ba Fa x Ns \\*(Ba
120*48352Scael= \*(If
121*48352Scaelor
122*48352Scael.Fa x
123*48352Scaellies between 0 and the Underflow Threshold.
124*48352Scael(See below under
125*48352Scael.Sx BUGS . )
126*48352Scael.Pp
127*48352ScaelThe
128*48352ScaelFn calb
129*48352Scaelreturns
130*48352Scael.Fa x Ns \(**(2** Ns Fa n )
131*48352Scaelcomputed, for integer n, without first computing
132*48352Scael.Pf 2\(** Fa n .
133*48352Scael.Sh RETURN VALUES
134*48352ScaelThe
135*48352Scael.Tn IEEE
136*48352Scaelstandard
137*48352Scael754 defines
138*48352Scael.Fn drem x 0
139*48352Scaeland
140*48352Scael.Fn drem \\*(If y
141*48352Scaelto be invalid operations that produce a \*(Na.
142*48352ScaelOn the
143*48352Scael.Tn VAX ,
144*48352Scael.Fn drem x 0
145*48352Scaelgenerates a reserved operand fault.  No \*(If
146*48352Scaelexists on a
147*48352Scael.Tn VAX .
148*48352Scael.Pp
149*48352Scael.Tn IEEE
150*48352Scael754 defines
15121079Smiriam.if n \
152*48352Scael.Fn logb \(+-\\*(If
153*48352Scael= \*(If and
154*48352Scael.Fn logb 0
155*48352Scael= \-\*(If, and
15624373Smiriamrequires the latter to signal Division\-by\-Zero.
157*48352ScaelBut on a
158*48352Scael.Tn VAX ,
159*48352Scael.Fn logb 0
160*48352Scael= 1.0 \- 2.0**31 = \-2,147,483,647.0.
161*48352ScaelAnd if the correct value of
162*48352Scael.Fn scalb
163*48352Scaelwould overflow on a
164*48352Scael.Tn VAX ,
165*48352Scaelit generates a reserved operand fault and sets the global variable
166*48352Scael.Va errno
167*48352Scaelto
168*48352Scael.Dv ERANGE .
169*48352Scael.Sh SEE ALSO
170*48352Scael.Xr floor 3 ,
171*48352Scael.Xr math 3 ,
172*48352Scael.Xr infnan 3
173*48352Scael.Sh AUTHOR
17424373SmiriamKwok\-Choi Ng
175*48352Scael.Sh HISTORY
176*48352ScaelThe
177*48352Scael.Nm ieee
178*48352Scaelfunctions appeared in
179*48352Scael.Bx 4.3 .
180*48352Scael.Sh BUGS
181*48352ScaelShould
182*48352Scael.Fn drem x 0
183*48352Scaeland
184*48352Scael.Fn logb 0
185*48352Scaelon a
186*48352Scael.Tn VAX
187*48352Scaelsignal invalidity
188*48352Scaelby setting
189*48352Scael.Va errno No = Dv EDOM ?
190*48352ScaelShould
191*48352Scael.Fn logb 0
192*48352Scaelreturn  \-1.7e38?
193*48352Scael.Pp
194*48352Scael.Tn IEEE
195*48352Scael754 currently specifies that
196*48352Scael.Fn logb "denormalized no."
197*48352Scael=
198*48352Scael.Fn logb "tiniest normalized no. > 0"
19924373Smiriambut the consensus has changed to the specification in the new
200*48352Scaelproposed
201*48352Scael.Tn IEEE
202*48352Scaelstandard p854, namely that
203*48352Scael.Fn logb x
204*48352Scaelsatisfy
205*48352Scael.Bd -filled -offset indent
206*48352Scael1 \(<=
207*48352Scael.Fn scalb \\*(Bax\\*(Ba \-logb(x)
208*48352Scael<
209*48352ScaelRadix\0 ... = 2
210*48352Scaelfor
211*48352Scael.Tn IEEE
212*48352Scael754
213*48352Scael.Ed
214*48352Scael.Pp
21524373Smiriamfor every x except 0,
216*48352Scael\*(If
217*48352Scaeland \*(Na.
21824373SmiriamAlmost every program that assumes 754's specification will work
219*48352Scaelcorrectly if
220*48352Scael.Fn logb
221*48352Scaelfollows 854's specification instead.
222*48352Scael.Pp
223*48352Scael.Tn IEEE
224*48352Scael754 requires
225*48352Scael.Fn copysign x \\*(Na)
226*48352Scael=
227*48352Scael.Pf \(+- Ns Fa x
228*48352Scaelbut says nothing
229*48352Scaelelse about the sign of a \*(Na.  A \*(Na
230*48352Scael.Em N Ns ot
231*48352Scael.Em a
232*48352Scael.Em N Ns umber )
233*48352Scaelis
234*48352Scaelsimilar in spirit to the
235*48352Scael.Tn VAX Ns 's
236*48352Scaelreserved operand, but very
23724373Smiriamdifferent in important details.  Since the sign bit of a
23824373Smiriamreserved operand makes it look negative,
239*48352Scael.Bd -filled -offset indent
240*48352Scael.Fn copysign x "reserved operand"
241*48352Scael=
242*48352Scael.Pf \- Fa x ;
243*48352Scael.Ed
244*48352Scael.Pp
24524373Smiriamshould this return the reserved operand instead?
246