xref: /csrg-svn/lib/libm/common_source/hypot.3 (revision 61301)
1*61301Sbostic.\" Copyright (c) 1985, 1991, 1993
2*61301Sbostic.\"	The Regents of the University of California.  All rights reserved.
324694Smckusick.\"
449229Scael.\" %sccs.include.redist.roff%
524694Smckusick.\"
6*61301Sbostic.\"     @(#)hypot.3	8.1 (Berkeley) 06/04/93
748352Scael.\"
848352Scael.Dd
948352Scael.Dt HYPOT 3
1048352Scael.Os BSD 4
1148352Scael.Sh NAME
1248352Scael.Nm hypot ,
1348352Scael.Nm cabs
1448352Scael.Nd euclidean distance and complex absolute value functions
1548352Scael.Sh SYNOPSIS
1648352Scael.Fd #include <math.h>
1748352Scael.Ft double
1848352Scael.Fn hypot "double x" "double y"
1948352Scael.Fd struct {double x, y;} z;
2048352Scael.Ft double
2148352Scael.Fn cabs z
2248352Scael.Sh DESCRIPTION
2348352ScaelThe
2448352Scael.Fn hypot
2548352Scaeland
2648352Scael.Fn cabs
2748352Scaelfunctions
2848352Scaelcomputes the
2948352Scaelsqrt(x*x+y*y)
3048352Scaelin such a way that underflow will not happen, and overflow
3124372Smiriamoccurs only if the final result deserves it.
3248352Scael.Pp
3348352Scael.Fn hypot "\*(If" "v"
3448352Scael=
3548352Scael.Fn hypot "v" "\*(If"
3648352Scael= +\*(If for all
3748352Scael.Ar v ,
3848352Scaelincluding \*(Na.
3948352Scael.Sh ERROR (due to Roundoff, etc.)
4048352ScaelBelow 0.97
4148352Scael.Em ulps .
4248352ScaelConsequently
4348352Scael.Fn hypot "5.0" "12.0"
4448352Scael= 13.0
4548352Scaelexactly;
4624372Smiriamin general, hypot and cabs return an integer whenever an
4724372Smiriaminteger might be expected.
4848352Scael.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
5148352Scaelexceed 1.2
5248352Scael.Em ulps .
5348352Scael.Sh NOTES
5448352ScaelAs might be expected,
5548352Scael.Fn hypot "v" "\*(Na"
5648352Scaeland
5748352Scael.Fn hypot "\*(Na" "v"
5848352Scaelare \*(Na for all
5948352Scael.Em finite
6048352Scael.Ar v ;
6148352Scaelwith "reserved operand" in place of "\*(Na", the
6248352Scaelsame is true on a
6348352Scael.Tn VAX .
6448352ScaelBut programmers on machines other than a
6548352Scael.Tn VAX
6648352Scael(if has no \*(If)
6724372Smiriammight be surprised at first to discover that
6848352Scael.Fn hypot "\(+-\*(If" "\*(Na"
6948352Scael= +\*(If.
7024372SmiriamThis is intentional; it happens because
7148352Scael.Fn hypot "\*(If" "v"
7248352Scael= +\*(If
7348352Scaelfor
7448352Scael.Em all
7548352Scael.Ar v ,
7648352Scaelfinite or infinite.
7724372SmiriamHence
7848352Scael.Fn hypot "\*(If" "v"
7948352Scaelis independent of
8048352Scael.Ar v .
8148352ScaelUnlike the reserved operand fault on a
8248352Scael.Tn VAX ,
8348352Scaelthe
8448352Scael.Tn IEEE
8548352Scael\*(Na is designed to
8624372Smiriamdisappear when it turns out to be irrelevant, as it does in
8748352Scael.Fn hypot "\*(If" "\*(Na" .
8848352Scael.Sh SEE ALSO
8948352Scael.Xr math 3 ,
9048352Scael.Xr sqrt 3
9148352Scael.Sh HISTORY
9248352ScaelBoth a
9348352Scael.Fn hypot
9448352Scaelfunction and a
9548352Scael.Fn cabs
9648352Scaelfunction
9748352Scaelappeared in
9848352Scael.At v7 .
99