|
|
1.1 ! root 1: .\" Copyright (c) 1985 Regents of the University of California. ! 2: .\" All rights reserved. The Berkeley software License Agreement ! 3: .\" specifies the terms and conditions for redistribution. ! 4: .\" ! 5: .\" @(#)hypot.3 6.5 (Berkeley) 5/12/86 ! 6: .\" ! 7: .TH HYPOT 3M "May 12, 1986" ! 8: .UC 4 ! 9: .ds up \fIulp\fR ! 10: .ds nn \fINaN\fR ! 11: .SH NAME ! 12: hypot, cabs \- Euclidean distance, complex absolute value ! 13: .SH SYNOPSIS ! 14: .nf ! 15: .B #include <math.h> ! 16: .PP ! 17: .B double hypot(x,y) ! 18: .B double x,y; ! 19: .PP ! 20: .B double cabs(z) ! 21: .B struct {double x,y;} z; ! 22: .fi ! 23: .SH DESCRIPTION ! 24: Hypot(x,y) and cabs(x,y) return sqrt(x\(**x+y\(**y) ! 25: computed in such a way that underflow will not happen, and overflow ! 26: occurs only if the final result deserves it. ! 27: .PP ! 28: .if n \ ! 29: hypot(infinity,v) = hypot(v,infinity) = +infinity for all v, ! 30: .if t \ ! 31: hypot(\(if,v) = hypot(v,\(if) = +\(if for all v, ! 32: including \*(nn. ! 33: .SH ERROR (due to Roundoff, etc.) ! 34: Below 0.97 \*(ups. Consequently hypot(5.0,12.0)\0=\013.0 exactly; ! 35: in general, hypot and cabs return an integer whenever an ! 36: integer might be expected. ! 37: .PP ! 38: The same cannot be said for the shorter and faster version of hypot ! 39: and cabs that is provided in the comments in cabs.c; its error can ! 40: exceed 1.2 \*(ups. ! 41: .SH NOTES ! 42: As might be expected, hypot(v,\*(nn) and hypot(\*(nn,v) are \*(nn for all ! 43: \fIfinite\fR v; with "reserved operand" in place of "\*(nn", the ! 44: same is true on a VAX. But programmers on machines other than a VAX ! 45: (it has no ! 46: .if n \ ! 47: infinity) ! 48: .if t \ ! 49: \(if) ! 50: might be surprised at first to discover that ! 51: .if n \ ! 52: hypot(\(+-infinity,\*(nn) = +infinity. ! 53: .if t \ ! 54: hypot(\(+-\(if,\*(nn) = +\(if. ! 55: This is intentional; it happens because ! 56: .if n \ ! 57: hypot(infinity,v) = +infinity ! 58: .if t \ ! 59: hypot(\(if,v) = +\(if ! 60: for \fIall\fR v, finite or infinite. ! 61: Hence ! 62: .if n \ ! 63: hypot(infinity,v) ! 64: .if t \ ! 65: hypot(\(if,v) ! 66: is independent of v. ! 67: Unlike the reserved operand on a VAX, the IEEE \*(nn is designed to ! 68: disappear when it turns out to be irrelevant, as it does in ! 69: .if n \ ! 70: hypot(infinity,\*(nn). ! 71: .if t \ ! 72: hypot(\(if,\*(nn). ! 73: .SH SEE ALSO ! 74: math(3M), sqrt(3M) ! 75: .SH AUTHOR ! 76: W. Kahan
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.