148352Scael.\" Copyright (c) 1985, 1991 Regents of the University of California. 248352Scael.\" All rights reserved. 324695Smckusick.\" 4*49229Scael.\" %sccs.include.redist.roff% 524695Smckusick.\" 6*49229Scael.\" @(#)ieee.3 6.4 (Berkeley) 05/06/91 748352Scael.\" 848352Scael.Dd 948352Scael.Dt IEEE 3 1048352Scael.Os BSD 4.3 1148352Scael.Sh NAME 1248352Scael.Nm copysign , 1348352Scael.Nm drem , 1448352Scael.Nm finite , 1548352Scael.Nm logb , 1648352Scael.Nm scalb 1748352Scael.Nm copysign , 1848352Scael.Nm remainder, 1948352Scael.Nd exponent manipulations 2048352Scael.Sh SYNOPSIS 2148352Scael.Fd #include <math.h> 2248352Scael.Ft double 2348352Scael.Fn copysign "double x" "double y" 2448352Scael.Ft double 2548352Scael.Fn drem "double x" "double y" 2648352Scael.Ft int 2748352Scael.Fn finite "double x" 2848352Scael.Ft double 2948352Scael.Fn logb "double x" 3048352Scael.Ft double 3148352Scael.Fn scalb "double x" "int n" 3248352Scael.Sh DESCRIPTION 3348352ScaelThese functions are required for, or recommended by the 3448352Scael.Tn IEEE 3548352Scaelstandard 3624373Smiriam754 for floating\-point arithmetic. 3748352Scael.Pp 3848352ScaelThe 3948352Scael.Fn copysign 4048352Scaelfunction 4148352Scaelreturns 4248352Scael.Fa x 4348352Scaelwith its sign changed to 4448352Scael.Fa y Ns 's. 4548352Scael.Pp 4648352ScaelThe 4748352Scael.Fn drem 4848352Scaelfunction 4948352Scaelreturns the remainder 5048352Scael.Fa r 5148352Scael:= 5248352Scael.Fa x 5348352Scael\- 5448352Scael.Fa n\(**y 5548352Scaelwhere 5648352Scael.Fa n 5748352Scaelis the integer nearest the exact value of 5848352Scael.Bk -words 5948352Scael.Fa x Ns / Ns Fa y ; 6048352Scael.Ek 6148352Scaelmoreover if 6248352Scael.Pf \\*(Ba Fa n 6348352Scael\- 6448352Scael.Sm off 6548352Scael.Fa x No / Fa y No \\*(Ba 6648352Scael.Sm on 6748352Scael= 6848352Scael1/2 6948352Scaelthen 7048352Scael.Fa n 7148352Scaelis even. Consequently 7248352Scaelthe remainder is computed exactly and 7348352Scael.Sm off 7448352Scael.Pf \\*(Ba Fa r No \\*(Ba 7548352Scael.Sm on 7648352Scael\*(Le 7748352Scael.Sm off 7848352Scael.Pf \\*(Ba Fa y No \\*(Ba/2. 7948352Scael.Sm on 8048352ScaelBut 8148352Scael.Fn drem x 0 8248352Scaelis exceptional. 8348352Scael(See below under 8448352Scael.Sx DIAGNOSTICS . ) 8548352Scael.Pp 8648352ScaelThe 8748352Scael.Fn finite 8848352Scaelfunction returns the value 1 just when 8948352Scael\-\*(If \*(Lt 9048352Scael.Fa x 9148352Scael\*(Lt +\*(If; 9248352Scaelotherwise a 9348352Scaelzero is returned 9448352Scael(when 9548352Scael.Pf \\*(Ba Ns Fa x Ns \\*(Ba 9648352Scael= \*(If or 9748352Scael.Fa x 9848352Scaelis \*(Na or 9948352Scaelis the 10048352Scael.Tn VAX Ns 's 10148352Scaelreserved operand). 10248352Scael.Pp 10348352ScaelThe 10448352Scael.Fn logb 10548352Scaelfunction returns 10648352Scael.Fa x Ns 's exponent 10748352Scael.Fa n , 10824373Smiriama signed integer converted to double\-precision floating\-point and so 10948352Scaelchosen that 11048352Scael1 (<= 11148352Scael.Pf \\*(Ba Ns Fa x Ns \\*(Ba2** Ns Fa n 11248352Scael< 2 11348352Scaelunless 11448352Scael.Fa x 11548352Scael= 0 or 11648352Scael(only on machines that conform to 11748352Scael.Tn IEEE 11848352Scael754) 11948352Scael.Pf \\*(Ba Fa x Ns \\*(Ba 12048352Scael= \*(If 12148352Scaelor 12248352Scael.Fa x 12348352Scaellies between 0 and the Underflow Threshold. 12448352Scael(See below under 12548352Scael.Sx BUGS . ) 12648352Scael.Pp 12748352ScaelThe 12848352ScaelFn calb 12948352Scaelreturns 13048352Scael.Fa x Ns \(**(2** Ns Fa n ) 13148352Scaelcomputed, for integer n, without first computing 13248352Scael.Pf 2\(** Fa n . 13348352Scael.Sh RETURN VALUES 13448352ScaelThe 13548352Scael.Tn IEEE 13648352Scaelstandard 13748352Scael754 defines 13848352Scael.Fn drem x 0 13948352Scaeland 14048352Scael.Fn drem \\*(If y 14148352Scaelto be invalid operations that produce a \*(Na. 14248352ScaelOn the 14348352Scael.Tn VAX , 14448352Scael.Fn drem x 0 14548352Scaelgenerates a reserved operand fault. No \*(If 14648352Scaelexists on a 14748352Scael.Tn VAX . 14848352Scael.Pp 14948352Scael.Tn IEEE 15048352Scael754 defines 15121079Smiriam.if n \ 15248352Scael.Fn logb \(+-\\*(If 15348352Scael= \*(If and 15448352Scael.Fn logb 0 15548352Scael= \-\*(If, and 15624373Smiriamrequires the latter to signal Division\-by\-Zero. 15748352ScaelBut on a 15848352Scael.Tn VAX , 15948352Scael.Fn logb 0 16048352Scael= 1.0 \- 2.0**31 = \-2,147,483,647.0. 16148352ScaelAnd if the correct value of 16248352Scael.Fn scalb 16348352Scaelwould overflow on a 16448352Scael.Tn VAX , 16548352Scaelit generates a reserved operand fault and sets the global variable 16648352Scael.Va errno 16748352Scaelto 16848352Scael.Dv ERANGE . 16948352Scael.Sh SEE ALSO 17048352Scael.Xr floor 3 , 17148352Scael.Xr math 3 , 17248352Scael.Xr infnan 3 17348352Scael.Sh HISTORY 17448352ScaelThe 17548352Scael.Nm ieee 17648352Scaelfunctions appeared in 17748352Scael.Bx 4.3 . 17848352Scael.Sh BUGS 17948352ScaelShould 18048352Scael.Fn drem x 0 18148352Scaeland 18248352Scael.Fn logb 0 18348352Scaelon a 18448352Scael.Tn VAX 18548352Scaelsignal invalidity 18648352Scaelby setting 18748352Scael.Va errno No = Dv EDOM ? 18848352ScaelShould 18948352Scael.Fn logb 0 19048352Scaelreturn \-1.7e38? 19148352Scael.Pp 19248352Scael.Tn IEEE 19348352Scael754 currently specifies that 19448352Scael.Fn logb "denormalized no." 19548352Scael= 19648352Scael.Fn logb "tiniest normalized no. > 0" 19724373Smiriambut the consensus has changed to the specification in the new 19848352Scaelproposed 19948352Scael.Tn IEEE 20048352Scaelstandard p854, namely that 20148352Scael.Fn logb x 20248352Scaelsatisfy 20348352Scael.Bd -filled -offset indent 20448352Scael1 \(<= 20548352Scael.Fn scalb \\*(Bax\\*(Ba \-logb(x) 20648352Scael< 20748352ScaelRadix\0 ... = 2 20848352Scaelfor 20948352Scael.Tn IEEE 21048352Scael754 21148352Scael.Ed 21248352Scael.Pp 21324373Smiriamfor every x except 0, 21448352Scael\*(If 21548352Scaeland \*(Na. 21624373SmiriamAlmost every program that assumes 754's specification will work 21748352Scaelcorrectly if 21848352Scael.Fn logb 21948352Scaelfollows 854's specification instead. 22048352Scael.Pp 22148352Scael.Tn IEEE 22248352Scael754 requires 22348352Scael.Fn copysign x \\*(Na) 22448352Scael= 22548352Scael.Pf \(+- Ns Fa x 22648352Scaelbut says nothing 22748352Scaelelse about the sign of a \*(Na. A \*(Na 22848352Scael.Em N Ns ot 22948352Scael.Em a 23048352Scael.Em N Ns umber ) 23148352Scaelis 23248352Scaelsimilar in spirit to the 23348352Scael.Tn VAX Ns 's 23448352Scaelreserved operand, but very 23524373Smiriamdifferent in important details. Since the sign bit of a 23624373Smiriamreserved operand makes it look negative, 23748352Scael.Bd -filled -offset indent 23848352Scael.Fn copysign x "reserved operand" 23948352Scael= 24048352Scael.Pf \- Fa x ; 24148352Scael.Ed 24248352Scael.Pp 24324373Smiriamshould this return the reserved operand instead? 244