xref: /original-bsd/lib/libm/common_source/ieee.3 (revision de3f5c4e)
1.\" Copyright (c) 1985, 1991 Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" %sccs.include.redist.roff%
5.\"
6.\"     @(#)ieee.3	6.4 (Berkeley) 05/06/91
7.\"
8.Dd
9.Dt IEEE 3
10.Os BSD 4.3
11.Sh NAME
12.Nm copysign ,
13.Nm drem ,
14.Nm finite ,
15.Nm logb ,
16.Nm scalb
17.Nm copysign ,
18.Nm remainder,
19.Nd exponent manipulations
20.Sh SYNOPSIS
21.Fd #include <math.h>
22.Ft double
23.Fn copysign "double x" "double y"
24.Ft double
25.Fn drem "double x" "double y"
26.Ft int
27.Fn finite "double x"
28.Ft double
29.Fn logb "double x"
30.Ft double
31.Fn scalb "double x" "int n"
32.Sh DESCRIPTION
33These functions are required for, or recommended by the
34.Tn IEEE
35standard
36754 for floating\-point arithmetic.
37.Pp
38The
39.Fn copysign
40function
41returns
42.Fa x
43with its sign changed to
44.Fa y Ns 's.
45.Pp
46The
47.Fn drem
48function
49returns the remainder
50.Fa r
51:=
52.Fa x
53\-
54.Fa n\(**y
55where
56.Fa n
57is the integer nearest the exact value of
58.Bk -words
59.Fa x Ns / Ns Fa y ;
60.Ek
61moreover if
62.Pf \\*(Ba Fa n
63\-
64.Sm off
65.Fa x No / Fa y No \\*(Ba
66.Sm on
67=
681/2
69then
70.Fa n
71is even.  Consequently
72the remainder is computed exactly and
73.Sm off
74.Pf \\*(Ba Fa r No \\*(Ba
75.Sm on
76\*(Le
77.Sm off
78.Pf \\*(Ba Fa y No \\*(Ba/2.
79.Sm on
80But
81.Fn drem x 0
82is exceptional.
83(See below under
84.Sx DIAGNOSTICS . )
85.Pp
86The
87.Fn finite
88function returns the value 1 just when
89\-\*(If \*(Lt
90.Fa x
91\*(Lt +\*(If;
92otherwise a
93zero is returned
94(when
95.Pf \\*(Ba Ns Fa x Ns \\*(Ba
96= \*(If or
97.Fa x
98is \*(Na or
99is the
100.Tn VAX Ns 's
101reserved operand).
102.Pp
103The
104.Fn logb
105function returns
106.Fa x Ns 's exponent
107.Fa n ,
108a signed integer converted to double\-precision floating\-point and so
109chosen that
1101 (<=
111.Pf \\*(Ba Ns Fa x Ns \\*(Ba2** Ns Fa n
112< 2
113unless
114.Fa x
115= 0 or
116(only on machines that conform to
117.Tn IEEE
118754)
119.Pf \\*(Ba Fa x Ns \\*(Ba
120= \*(If
121or
122.Fa x
123lies between 0 and the Underflow Threshold.
124(See below under
125.Sx BUGS . )
126.Pp
127The
128Fn calb
129returns
130.Fa x Ns \(**(2** Ns Fa n )
131computed, for integer n, without first computing
132.Pf 2\(** Fa n .
133.Sh RETURN VALUES
134The
135.Tn IEEE
136standard
137754 defines
138.Fn drem x 0
139and
140.Fn drem \\*(If y
141to be invalid operations that produce a \*(Na.
142On the
143.Tn VAX ,
144.Fn drem x 0
145generates a reserved operand fault.  No \*(If
146exists on a
147.Tn VAX .
148.Pp
149.Tn IEEE
150754 defines
151.if n \
152.Fn logb \(+-\\*(If
153= \*(If and
154.Fn logb 0
155= \-\*(If, and
156requires the latter to signal Division\-by\-Zero.
157But on a
158.Tn VAX ,
159.Fn logb 0
160= 1.0 \- 2.0**31 = \-2,147,483,647.0.
161And if the correct value of
162.Fn scalb
163would overflow on a
164.Tn VAX ,
165it generates a reserved operand fault and sets the global variable
166.Va errno
167to
168.Dv ERANGE .
169.Sh SEE ALSO
170.Xr floor 3 ,
171.Xr math 3 ,
172.Xr infnan 3
173.Sh HISTORY
174The
175.Nm ieee
176functions appeared in
177.Bx 4.3 .
178.Sh BUGS
179Should
180.Fn drem x 0
181and
182.Fn logb 0
183on a
184.Tn VAX
185signal invalidity
186by setting
187.Va errno No = Dv EDOM ?
188Should
189.Fn logb 0
190return  \-1.7e38?
191.Pp
192.Tn IEEE
193754 currently specifies that
194.Fn logb "denormalized no."
195=
196.Fn logb "tiniest normalized no. > 0"
197but the consensus has changed to the specification in the new
198proposed
199.Tn IEEE
200standard p854, namely that
201.Fn logb x
202satisfy
203.Bd -filled -offset indent
2041 \(<=
205.Fn scalb \\*(Bax\\*(Ba \-logb(x)
206<
207Radix\0 ... = 2
208for
209.Tn IEEE
210754
211.Ed
212.Pp
213for every x except 0,
214\*(If
215and \*(Na.
216Almost every program that assumes 754's specification will work
217correctly if
218.Fn logb
219follows 854's specification instead.
220.Pp
221.Tn IEEE
222754 requires
223.Fn copysign x \\*(Na)
224=
225.Pf \(+- Ns Fa x
226but says nothing
227else about the sign of a \*(Na.  A \*(Na
228.Em N Ns ot
229.Em a
230.Em N Ns umber )
231is
232similar in spirit to the
233.Tn VAX Ns 's
234reserved operand, but very
235different in important details.  Since the sign bit of a
236reserved operand makes it look negative,
237.Bd -filled -offset indent
238.Fn copysign x "reserved operand"
239=
240.Pf \- Fa x ;
241.Ed
242.Pp
243should this return the reserved operand instead?
244