1*48352Scael.\" Copyright (c) 1985, 1991 Regents of the University of California. 2*48352Scael.\" All rights reserved. 324694Smckusick.\" 4*48352Scael.\" %sccs.include.redist.man% 524694Smckusick.\" 6*48352Scael.\" @(#)hypot.3 6.6 (Berkeley) 04/19/91 7*48352Scael.\" 8*48352Scael.Dd 9*48352Scael.Dt HYPOT 3 10*48352Scael.Os BSD 4 11*48352Scael.Sh NAME 12*48352Scael.Nm hypot , 13*48352Scael.Nm cabs 14*48352Scael.Nd euclidean distance and complex absolute value functions 15*48352Scael.Sh SYNOPSIS 16*48352Scael.Fd #include <math.h> 17*48352Scael.Ft double 18*48352Scael.Fn hypot "double x" "double y" 19*48352Scael.Fd struct {double x, y;} z; 20*48352Scael.Ft double 21*48352Scael.Fn cabs z 22*48352Scael.Sh DESCRIPTION 23*48352ScaelThe 24*48352Scael.Fn hypot 25*48352Scaeland 26*48352Scael.Fn cabs 27*48352Scaelfunctions 28*48352Scaelcomputes the 29*48352Scaelsqrt(x*x+y*y) 30*48352Scaelin such a way that underflow will not happen, and overflow 3124372Smiriamoccurs only if the final result deserves it. 32*48352Scael.Pp 33*48352Scael.Fn hypot "\*(If" "v" 34*48352Scael= 35*48352Scael.Fn hypot "v" "\*(If" 36*48352Scael= +\*(If for all 37*48352Scael.Ar v , 38*48352Scaelincluding \*(Na. 39*48352Scael.Sh ERROR (due to Roundoff, etc.) 40*48352ScaelBelow 0.97 41*48352Scael.Em ulps . 42*48352ScaelConsequently 43*48352Scael.Fn hypot "5.0" "12.0" 44*48352Scael= 13.0 45*48352Scaelexactly; 4624372Smiriamin general, hypot and cabs return an integer whenever an 4724372Smiriaminteger might be expected. 48*48352Scael.Pp 4924372SmiriamThe same cannot be said for the shorter and faster version of hypot 5024372Smiriamand cabs that is provided in the comments in cabs.c; its error can 51*48352Scaelexceed 1.2 52*48352Scael.Em ulps . 53*48352Scael.Sh NOTES 54*48352ScaelAs might be expected, 55*48352Scael.Fn hypot "v" "\*(Na" 56*48352Scaeland 57*48352Scael.Fn hypot "\*(Na" "v" 58*48352Scaelare \*(Na for all 59*48352Scael.Em finite 60*48352Scael.Ar v ; 61*48352Scaelwith "reserved operand" in place of "\*(Na", the 62*48352Scaelsame is true on a 63*48352Scael.Tn VAX . 64*48352ScaelBut programmers on machines other than a 65*48352Scael.Tn VAX 66*48352Scael(if has no \*(If) 6724372Smiriammight be surprised at first to discover that 68*48352Scael.Fn hypot "\(+-\*(If" "\*(Na" 69*48352Scael= +\*(If. 7024372SmiriamThis is intentional; it happens because 71*48352Scael.Fn hypot "\*(If" "v" 72*48352Scael= +\*(If 73*48352Scaelfor 74*48352Scael.Em all 75*48352Scael.Ar v , 76*48352Scaelfinite or infinite. 7724372SmiriamHence 78*48352Scael.Fn hypot "\*(If" "v" 79*48352Scaelis independent of 80*48352Scael.Ar v . 81*48352ScaelUnlike the reserved operand fault on a 82*48352Scael.Tn VAX , 83*48352Scaelthe 84*48352Scael.Tn IEEE 85*48352Scael\*(Na is designed to 8624372Smiriamdisappear when it turns out to be irrelevant, as it does in 87*48352Scael.Fn hypot "\*(If" "\*(Na" . 88*48352Scael.Sh SEE ALSO 89*48352Scael.Xr math 3 , 90*48352Scael.Xr sqrt 3 91*48352Scael.Sh AUTHOR 92*48352Scael.An W. Kahan 93*48352Scael.Sh HISTORY 94*48352ScaelBoth a 95*48352Scael.Fn hypot 96*48352Scaelfunction and a 97*48352Scael.Fn cabs 98*48352Scaelfunction 99*48352Scaelappeared in 100*48352Scael.At v7 . 101