Commit | Line | Data |
---|---|---|
ef8ea0f5 | 1 | From 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 |
6 | copysign, drem, finite, logb, scalb \- copysign, remainder, |
7 | exponent 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 |
29 | These functions are required for, or recommended by the IEEE standard |
30 | 754 for floating\-point arithmetic. | |
ef8ea0f5 | 31 | .PP |
cd30a7d2 MAN |
32 | Copysign(x,y) |
33 | returns x with its sign changed to y's. | |
ef8ea0f5 | 34 | .PP |
cd30a7d2 MAN |
35 | Drem(x,y) returns the remainder r := x \- n\(**y |
36 | where n is the integer nearest the exact value of x/y; | |
37 | moreover if |n\|\-\|x/y|\|=\|1/2 then n is even. Consequently | |
38 | the remainder is computed exactly and |r| \(<= |y|/2. But | |
39 | drem(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 | 44 | Finite(x) = 1 just when \-infinity < x < +infinity, |
f7102ab2 | 45 | .if t \ |
cd30a7d2 | 46 | Finite(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 | |
55 | Logb(x) returns x's exponent n, | |
56 | a signed integer converted to double\-precision floating\-point and so | |
57 | chosen 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 |
63 | or x lies between 0 and the Underflow Threshold; see below under "BUGS". | |
64 | .PP | |
65 | Scalb(x,n) = x\(**(2**n) computed, for integer n, without first computing | |
66 | 2**n. | |
ef8ea0f5 | 67 | .SH SEE ALSO |
cd30a7d2 | 68 | intro(3M), infnan(3M) |
ef8ea0f5 | 69 | .SH DIAGNOSTICS |
cd30a7d2 MAN |
70 | IEEE 754 defines drem(x,0) and |
71 | .if n \ | |
72 | drem(infinity,y) | |
73 | .if t \ | |
74 | drem(\(if,y) | |
75 | to be invalid operations that produce a \*(nn. | |
76 | On a VAX, drem(x,0) returns the reserved operand. No | |
77 | .if n \ | |
78 | infinity | |
79 | .if t \ | |
80 | \(if | |
81 | exists on a VAX. | |
82 | .PP | |
83 | IEEE 754 defines | |
84 | .if n \ | |
85 | logb(\(+-infinity) = +infinity and logb(0) = \-infinity, | |
86 | .if t \ | |
87 | logb(\(+-\(if) = +\(if and logb(0) = \-\(if, and | |
88 | requires the latter to signal Division\-by\-Zero. | |
89 | But on a VAX, logb(0) = 1.0 \- 2.0**31 = \-2,147,483,647.0. | |
90 | And if the correct value of scalb(x,n) would overflow on a VAX, | |
91 | it returns the reserved operand and sets \fIerrno\fR to ERANGE. | |
ef8ea0f5 | 92 | .SH AUTHOR |
cd30a7d2 | 93 | Kwok\-Choi Ng |
ef8ea0f5 | 94 | .SH BUGS |
cd30a7d2 MAN |
95 | Should drem(x,0) and logb(0) on a VAX signal invalidity |
96 | by setting \fIerrno\fR = EDOM? Should logb(0) return \-1.7e38? | |
97 | .PP | |
98 | IEEE 754 currently specifies that | |
99 | logb(denormalized no.) = logb(tiniest normalized no. > 0) | |
100 | but the consensus has changed to the specification in the new | |
101 | proposed IEEE standard p854, namely that logb(x) satisfy | |
102 | .RS | |
103 | 1 \(<= scalb(|x|,\-logb(x)) < Radix\0\0\0... = 2 for IEEE 754 | |
104 | .RE | |
105 | for every x except 0, | |
106 | .if n \ | |
107 | infinity | |
108 | .if t \ | |
109 | \(if | |
110 | and \*(nn. | |
111 | Almost every program that assumes 754's specification will work | |
112 | correctly if logb follows 854's specification instead. | |
113 | .PP | |
114 | IEEE 754 requires copysign(x,\*(nn) = \(+-x but says nothing | |
115 | else about the sign of a \*(nn. A \*(nn (\fIN\fRot \fIa\fR \fIN\fRumber) is | |
116 | similar in spirit to the VAX's reserved operand, but very | |
117 | different in important details. Since the sign bit of a | |
118 | reserved operand makes it look negative, | |
119 | .RS | |
120 | copysign(x,reserved operand) = \-x; | |
121 | .RE | |
122 | should this return the reserved operand instead? |