1.\" Copyright (c) 1985, 1991 Regents of the University of California. 2.\" All rights reserved. 3.\" 4.\" %sccs.include.redist.man% 5.\" 6.\" @(#)ieee.3 6.3 (Berkeley) 04/19/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 AUTHOR 174Kwok\-Choi Ng 175.Sh HISTORY 176The 177.Nm ieee 178functions appeared in 179.Bx 4.3 . 180.Sh BUGS 181Should 182.Fn drem x 0 183and 184.Fn logb 0 185on a 186.Tn VAX 187signal invalidity 188by setting 189.Va errno No = Dv EDOM ? 190Should 191.Fn logb 0 192return \-1.7e38? 193.Pp 194.Tn IEEE 195754 currently specifies that 196.Fn logb "denormalized no." 197= 198.Fn logb "tiniest normalized no. > 0" 199but the consensus has changed to the specification in the new 200proposed 201.Tn IEEE 202standard p854, namely that 203.Fn logb x 204satisfy 205.Bd -filled -offset indent 2061 \(<= 207.Fn scalb \\*(Bax\\*(Ba \-logb(x) 208< 209Radix\0 ... = 2 210for 211.Tn IEEE 212754 213.Ed 214.Pp 215for every x except 0, 216\*(If 217and \*(Na. 218Almost every program that assumes 754's specification will work 219correctly if 220.Fn logb 221follows 854's specification instead. 222.Pp 223.Tn IEEE 224754 requires 225.Fn copysign x \\*(Na) 226= 227.Pf \(+- Ns Fa x 228but says nothing 229else about the sign of a \*(Na. A \*(Na 230.Em N Ns ot 231.Em a 232.Em N Ns umber ) 233is 234similar in spirit to the 235.Tn VAX Ns 's 236reserved operand, but very 237different in important details. Since the sign bit of a 238reserved operand makes it look negative, 239.Bd -filled -offset indent 240.Fn copysign x "reserved operand" 241= 242.Pf \- Fa x ; 243.Ed 244.Pp 245should this return the reserved operand instead? 246