HYPOT(3) BSD Programmer's Manual HYPOT(3) NNAAMMEE hhyyppoott, ccaabbss - euclidean distance and complex absolute value functions SSYYNNOOPPSSIISS ##iinncclluuddee <<mmaatthh..hh>> _d_o_u_b_l_e hhyyppoott(_d_o_u_b_l_e _x, _d_o_u_b_l_e _y); ssttrruucctt {{ddoouubbllee xx,, yy;;}} zz;; _d_o_u_b_l_e ccaabbss(_z); DDEESSCCRRIIPPTTIIOONN The hhyyppoott() and ccaabbss() functions computes the sqrt(x*x+y*y) in such a way that underflow will not happen, and overflow occurs only if the final re- sult deserves it. hhyyppoott(_i_n_f_i_n_i_t_y, _v) = hhyyppoott(_v, _i_n_f_i_n_i_t_y) = +infinity for all _v, including _N_a_N. EERRRROORR ((dduuee ttoo RRoouunnddooffff,, eettcc..)) Below 0.97 _u_l_p_s. Consequently hhyyppoott(_5_._0, _1_2_._0) = 13.0 exactly; in gener- al, hypot and cabs return an integer whenever an integer might be expect- ed. The same cannot be said for the shorter and faster version of hypot and cabs that is provided in the comments in cabs.c; its error can exceed 1.2 _u_l_p_s. NNOOTTEESS As might be expected, hhyyppoott(_v, _N_a_N) and hhyyppoott(_N_a_N, _v) are _N_a_N for all _f_i_n_i_t_e _v; with "reserved operand" in place of "_N_a_N", the same is true on a VAX. But programmers on machines other than a VAX (if has no infinity) might be surprised at first to discover that hhyyppoott(_+_-_i_n_f_i_n_i_t_y, _N_a_N) = +infinity. This is intentional; it happens because hhyyppoott(_i_n_f_i_n_i_t_y, _v) = +infinity for _a_l_l _v, finite or infinite. Hence hhyyppoott(_i_n_f_i_n_i_t_y, _v) is in- dependent of _v. Unlike the reserved operand fault on a VAX, the IEEE _N_a_N is designed to disappear when it turns out to be irrelevant, as it does in hhyyppoott(_i_n_f_i_n_i_t_y, _N_a_N). SSEEEE AALLSSOO math(3), sqrt(3) HHIISSTTOORRYY Both a hhyyppoott() function and a ccaabbss() function appeared in Version 7 AT&T UNIX. 4th Berkeley Distribution June 4, 1993 1