date and time created 85/08/21 15:33:50 by miriam
[unix-history] / usr / src / lib / libm / common_source / ieee.3
CommitLineData
ef8ea0f5 1From Prof. Kahan at UC at Berkeley
cd30a7d2 2.TH IEEE 3M "7 August 1985"
ef8ea0f5 3.UC 4
cd30a7d2 4.ds nn \fINaN\fR
ef8ea0f5 5.SH NAME
cd30a7d2
MAN
6copysign, drem, finite, logb, scalb \- copysign, remainder,
7exponent manipulations
ef8ea0f5
MAN
8.SH SYNOPSIS
9.nf
10.B #include <math.h>
11.PP
cd30a7d2
MAN
12.B double copysign(x,y)
13.B double x,y;
ef8ea0f5 14.PP
cd30a7d2
MAN
15.B double drem(x,y)
16.B double x,y;
17.PP
18.B int finite(x)
19.B double x;
ef8ea0f5
MAN
20.PP
21.B double logb(x)
22.B double x;
23.PP
cd30a7d2 24.B double scalb(x,n)
ef8ea0f5
MAN
25.B double x;
26.B int n;
27.fi
28.SH DESCRIPTION
cd30a7d2
MAN
29These functions are required for, or recommended by the IEEE standard
30754 for floating\-point arithmetic.
ef8ea0f5 31.PP
cd30a7d2
MAN
32Copysign(x,y)
33returns x with its sign changed to y's.
ef8ea0f5 34.PP
cd30a7d2
MAN
35Drem(x,y) returns the remainder r := x \- n\(**y
36where n is the integer nearest the exact value of x/y;
37moreover if |n\|\-\|x/y|\|=\|1/2 then n is even. Consequently
38the remainder is computed exactly and |r| \(<= |y|/2. But
39drem(x,0) is exceptional; see below under DIAGNOSTICS.
ef8ea0f5 40.PP
cd30a7d2
MAN
41.nf
42.ta \w'Finite(x)'u+1n +\w'= 0 otherwise'u+1n
f7102ab2 43.if n \
cd30a7d2 44Finite(x) = 1 just when \-infinity < x < +infinity,
f7102ab2 45.if t \
cd30a7d2 46Finite(x) = 1 just when \-\(if < x < +\(if,
8e5419e4 47.if n \
cd30a7d2 48 = 0 otherwise (when |x| = infinity or x is \*(nn or
8e5419e4 49.if t \
cd30a7d2
MAN
50 = 0 otherwise (when |x| = \(if or x is \*(nn or
51 \0x is the VAX's reserved operand.)
52.ta
53.fi
54.PP
55Logb(x) returns x's exponent n,
56a signed integer converted to double\-precision floating\-point and so
57chosen that 1\0\(<=\0|x|/2**n\0<\02 unless x = 0 or
58(only on machines that conform to IEEE 754)
8e5419e4 59.if n \
cd30a7d2 60|x| = infinity
8e5419e4 61.if t \
cd30a7d2
MAN
62|x| = \(if
63or x lies between 0 and the Underflow Threshold; see below under "BUGS".
64.PP
65Scalb(x,n) = x\(**(2**n) computed, for integer n, without first computing
662**n.
ef8ea0f5 67.SH SEE ALSO
cd30a7d2 68intro(3M), infnan(3M)
ef8ea0f5 69.SH DIAGNOSTICS
cd30a7d2
MAN
70IEEE 754 defines drem(x,0) and
71.if n \
72drem(infinity,y)
73.if t \
74drem(\(if,y)
75to be invalid operations that produce a \*(nn.
76On a VAX, drem(x,0) returns the reserved operand. No
77.if n \
78infinity
79.if t \
80\(if
81exists on a VAX.
82.PP
83IEEE 754 defines
84.if n \
85logb(\(+-infinity) = +infinity and logb(0) = \-infinity,
86.if t \
87logb(\(+-\(if) = +\(if and logb(0) = \-\(if, and
88requires the latter to signal Division\-by\-Zero.
89But on a VAX, logb(0) = 1.0 \- 2.0**31 = \-2,147,483,647.0.
90And if the correct value of scalb(x,n) would overflow on a VAX,
91it returns the reserved operand and sets \fIerrno\fR to ERANGE.
ef8ea0f5 92.SH AUTHOR
cd30a7d2 93Kwok\-Choi Ng
ef8ea0f5 94.SH BUGS
cd30a7d2
MAN
95Should drem(x,0) and logb(0) on a VAX signal invalidity
96by setting \fIerrno\fR = EDOM? Should logb(0) return \-1.7e38?
97.PP
98IEEE 754 currently specifies that
99logb(denormalized no.) = logb(tiniest normalized no. > 0)
100but the consensus has changed to the specification in the new
101proposed IEEE standard p854, namely that logb(x) satisfy
102.RS
1031 \(<= scalb(|x|,\-logb(x)) < Radix\0\0\0... = 2 for IEEE 754
104.RE
105for every x except 0,
106.if n \
107infinity
108.if t \
109\(if
110and \*(nn.
111Almost every program that assumes 754's specification will work
112correctly if logb follows 854's specification instead.
113.PP
114IEEE 754 requires copysign(x,\*(nn) = \(+-x but says nothing
115else about the sign of a \*(nn. A \*(nn (\fIN\fRot \fIa\fR \fIN\fRumber) is
116similar in spirit to the VAX's reserved operand, but very
117different in important details. Since the sign bit of a
118reserved operand makes it look negative,
119.RS
120copysign(x,reserved operand) = \-x;
121.RE
122should this return the reserved operand instead?