1HYPOT(3) 386BSD Programmer's Manual HYPOT(3) 2 3NNAAMMEE 4 hhyyppoott, ccaabbss - euclidean distance and complex absolute value functions 5 6SSYYNNOOPPSSIISS 7 ##iinncclluuddee <<mmaatthh..hh>> 8 9 _d_o_u_b_l_e 10 hhyyppoott(_d_o_u_b_l_e _x, _d_o_u_b_l_e _y) 11 12 ssttrruucctt {{ddoouubbllee xx,, yy;;}} zz;; 13 14 _d_o_u_b_l_e 15 ccaabbss(_z) 16 17DDEESSCCRRIIPPTTIIOONN 18 The hhyyppoott() and ccaabbss() functions computes the sqrt(x*x+y*y) in such a way 19 that underflow will not happen, and overflow occurs only if the final 20 result deserves it. 21 22 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 23 _N_a_N. 24 25EERRRROORR ((dduuee ttoo RRoouunnddooffff,, eettcc..)) 26 Below 0.97 _u_l_p_s. Consequently hhyyppoott(_5._0, _1_2._0) = 13.0 exactly; in 27 general, hypot and cabs return an integer whenever an integer might be 28 expected. 29 30 The same cannot be said for the shorter and faster version of hypot and 31 cabs that is provided in the comments in cabs.c; its error can exceed 1.2 32 _u_l_p_s. 33 34NNOOTTEESS 35 As might be expected, hhyyppoott(_v, _N_a_N) and hhyyppoott(_N_a_N, _v) are _N_a_N for all 36 _f_i_n_i_t_e _v; with "reserved operand" in place of "_N_a_N", the same is true on 37 a VAX. But programmers on machines other than a VAX (if has no infinity) 38 might be surprised at first to discover that hhyyppoott(+-_i_n_f_i_n_i_t_y, _N_a_N) = 39 +infinity. This is intentional; it happens because hhyyppoott(_i_n_f_i_n_i_t_y, _v) = 40 +infinity for _a_l_l _v, finite or infinite. Hence hhyyppoott(_i_n_f_i_n_i_t_y, _v) is 41 independent of _v. Unlike the reserved operand fault on a VAX, the IEEE 42 _N_a_N is designed to disappear when it turns out to be irrelevant, as it 43 does in hhyyppoott(_i_n_f_i_n_i_t_y, _N_a_N). 44 45SSEEEE AALLSSOO 46 math(3), sqrt(3) 47 48HHIISSTTOORRYY 49 Both a hhyyppoott() function and a ccaabbss() function appeared in Version 7 AT&T 50 UNIX. 51 524th Berkeley Distribution May 6, 1991 1 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67