IEEE(3) BSD Programmer's Manual IEEE(3) NNAAMMEE ccooppyyssiiggnn, ddrreemm, ffiinniittee, llooggbb, ssccaallbb - IEEE 754 floating point support SSYYNNOOPPSSIISS ##iinncclluuddee <> _d_o_u_b_l_e ccooppyyssiiggnn(_d_o_u_b_l_e _x, _d_o_u_b_l_e _y); _d_o_u_b_l_e ddrreemm(_d_o_u_b_l_e _x, _d_o_u_b_l_e _y); _i_n_t ffiinniittee(_d_o_u_b_l_e _x); _d_o_u_b_l_e llooggbb(_d_o_u_b_l_e _x); _d_o_u_b_l_e ssccaallbb(_d_o_u_b_l_e _x, _i_n_t _n); DDEESSCCRRIIPPTTIIOONN These functions are required for, or recommended by the IEEE standard 754 for floating-point arithmetic. The ccooppyyssiiggnn() function returns _x with its sign changed to _y's. The ddrreemm() function returns the remainder _r := _x - _n_*_y where _n is the in- teger nearest the exact value of _x/_y; moreover if |_n - _x/_y| = 1/2 then _n is even. Consequently the remainder is computed exactly and |_r| <= |_y|/2. But ddrreemm(_x, _0) is exceptional. (See below under _D_I_A_G_N_O_S_T_I_C_S.) The ffiinniittee() function returns the value 1 just when -infinity < _x < +in- finity; otherwise a zero is returned (when |_x| = infinity or _x is _N_a_N or is the VAX's reserved operand). The llooggbb() function returns _x's exponent _n, a signed integer converted to double-precision floating-point and so chosen that 1 (<= |_x|2**_n < 2 un- less _x = 0 or (only on machines that conform to IEEE 754) |_x| = infinity or _x lies between 0 and the Underflow Threshold. (See below under _B_U_G_S.) The ssccaallbb() function returns _x*(2**_n) computed, for integer n, without first computing 2*_n. RREETTUURRNN VVAALLUUEESS The IEEE standard 754 defines ddrreemm(_x, _0) and ddrreemm(_i_n_f_i_n_i_t_y, _y) to be in- valid operations that produce a _N_a_N. On the VAX, ddrreemm(_x, _0) generates a reserved operand fault. No infinity exists on a VAX. IEEE 754 defines llooggbb(_+_-_i_n_f_i_n_i_t_y) = infinity and llooggbb(_0) = -infinity, and requires the latter to signal Division-by-Zero. But on a VAX, llooggbb(_0) = 1.0 - 2.0**31 = -2,147,483,647.0. And if the correct value of ssccaallbb() would overflow on a VAX, it generates a reserved operand fault and sets the global variable _e_r_r_n_o to ERANGE. SSEEEE AALLSSOO floor(3), math(3), infnan(3) HHIISSTTOORRYY The iieeeeee functions appeared in 4.3BSD. BBUUGGSS Should ddrreemm(_x, _0) and llooggbb(_0) on a VAX signal invalidity by setting _e_r_r_n_o = EDOM ? Should llooggbb(_0) return -1.7e38? IEEE 754 currently specifies that llooggbb(_d_e_n_o_r_m_a_l_i_z_e_d _n_o_.) = llooggbb(_t_i_n_i_e_s_t _n_o_r_m_a_l_i_z_e_d _n_o_. _> _0) but the consensus has changed to the specification in the new proposed IEEE standard p854, namely that llooggbb(_x) satisfy 1 <= ssccaallbb(|_x|, _-_l_o_g_b_(_x_)) < Radix ... = 2 for IEEE 754 for every x except 0, infinity and _N_a_N. Almost every program that as- sumes 754's specification will work correctly if llooggbb() follows 854's specification instead. IEEE 754 requires ccooppyyssiiggnn(_x, _N_a_N_)) = +-_x but says nothing else about the sign of a _N_a_N. A _N_a_N _(_Not _a _Number) is similar in spirit to the VAX's reserved operand, but very different in important details. Since the sign bit of a reserved operand makes it look negative, ccooppyyssiiggnn(_x, _r_e_s_e_r_v_e_d _o_p_e_r_a_n_d) = -_x; should this return the reserved operand instead? 4.3 Berkeley Distribution June 4, 1993 2