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