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.\" @(#)hypot.3 8.1 (Berkeley) 06/04/93 7.\" 8.Dd 9.Dt HYPOT 3 10.Os BSD 4 11.Sh NAME 12.Nm hypot , 13.Nm cabs 14.Nd euclidean distance and complex absolute value functions 15.Sh SYNOPSIS 16.Fd #include <math.h> 17.Ft double 18.Fn hypot "double x" "double y" 19.Fd struct {double x, y;} z; 20.Ft double 21.Fn cabs z 22.Sh DESCRIPTION 23The 24.Fn hypot 25and 26.Fn cabs 27functions 28computes the 29sqrt(x*x+y*y) 30in such a way that underflow will not happen, and overflow 31occurs only if the final result deserves it. 32.Pp 33.Fn hypot "\*(If" "v" 34= 35.Fn hypot "v" "\*(If" 36= +\*(If for all 37.Ar v , 38including \*(Na. 39.Sh ERROR (due to Roundoff, etc.) 40Below 0.97 41.Em ulps . 42Consequently 43.Fn hypot "5.0" "12.0" 44= 13.0 45exactly; 46in general, hypot and cabs return an integer whenever an 47integer might be expected. 48.Pp 49The same cannot be said for the shorter and faster version of hypot 50and cabs that is provided in the comments in cabs.c; its error can 51exceed 1.2 52.Em ulps . 53.Sh NOTES 54As might be expected, 55.Fn hypot "v" "\*(Na" 56and 57.Fn hypot "\*(Na" "v" 58are \*(Na for all 59.Em finite 60.Ar v ; 61with "reserved operand" in place of "\*(Na", the 62same is true on a 63.Tn VAX . 64But programmers on machines other than a 65.Tn VAX 66(if has no \*(If) 67might be surprised at first to discover that 68.Fn hypot "\(+-\*(If" "\*(Na" 69= +\*(If. 70This is intentional; it happens because 71.Fn hypot "\*(If" "v" 72= +\*(If 73for 74.Em all 75.Ar v , 76finite or infinite. 77Hence 78.Fn hypot "\*(If" "v" 79is independent of 80.Ar v . 81Unlike the reserved operand fault on a 82.Tn VAX , 83the 84.Tn IEEE 85\*(Na is designed to 86disappear when it turns out to be irrelevant, as it does in 87.Fn hypot "\*(If" "\*(Na" . 88.Sh SEE ALSO 89.Xr math 3 , 90.Xr sqrt 3 91.Sh HISTORY 92Both a 93.Fn hypot 94function and a 95.Fn cabs 96function 97appeared in 98.At v7 . 99