BSD 4_4 development
[unix-history] / usr / share / man / cat3 / cabs.0
HYPOT(3) BSD Programmer's Manual HYPOT(3)
N\bNA\bAM\bME\bE
h\bhy\byp\bpo\bot\bt, c\bca\bab\bbs\bs - euclidean distance and complex absolute value functions
S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS
#\b#i\bin\bnc\bcl\blu\bud\bde\be <\b<m\bma\bat\bth\bh.\b.h\bh>\b>
_\bd_\bo_\bu_\bb_\bl_\be
h\bhy\byp\bpo\bot\bt(_\bd_\bo_\bu_\bb_\bl_\be _\bx, _\bd_\bo_\bu_\bb_\bl_\be _\by);
s\bst\btr\bru\buc\bct\bt {\b{d\bdo\bou\bub\bbl\ble\be x\bx,\b, y\by;\b;}\b} z\bz;\b;
_\bd_\bo_\bu_\bb_\bl_\be
c\bca\bab\bbs\bs(_\bz);
D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
The h\bhy\byp\bpo\bot\bt() and c\bca\bab\bbs\bs() functions computes the sqrt(x*x+y*y) in such a way
that underflow will not happen, and overflow occurs only if the final re-
sult deserves it.
h\bhy\byp\bpo\bot\bt(_\bi_\bn_\bf_\bi_\bn_\bi_\bt_\by, _\bv) = h\bhy\byp\bpo\bot\bt(_\bv, _\bi_\bn_\bf_\bi_\bn_\bi_\bt_\by) = +infinity for all _\bv, including
_\bN_\ba_\bN.
E\bER\bRR\bRO\bOR\bR (\b(d\bdu\bue\be t\bto\bo R\bRo\bou\bun\bnd\bdo\bof\bff\bf,\b, e\bet\btc\bc.\b.)\b)
Below 0.97 _\bu_\bl_\bp_\bs. Consequently h\bhy\byp\bpo\bot\bt(_\b5_\b._\b0, _\b1_\b2_\b._\b0) = 13.0 exactly; in gener-
al, hypot and cabs return an integer whenever an integer might be expect-
ed.
The same cannot be said for the shorter and faster version of hypot and
cabs that is provided in the comments in cabs.c; its error can exceed 1.2
_\bu_\bl_\bp_\bs.
N\bNO\bOT\bTE\bES\bS
As might be expected, h\bhy\byp\bpo\bot\bt(_\bv, _\bN_\ba_\bN) and h\bhy\byp\bpo\bot\bt(_\bN_\ba_\bN, _\bv) are _\bN_\ba_\bN for all
_\bf_\bi_\bn_\bi_\bt_\be _\bv; with "reserved operand" in place of "_\bN_\ba_\bN", the same is true on
a VAX. But programmers on machines other than a VAX (if has no infinity)
might be surprised at first to discover that h\bhy\byp\bpo\bot\bt(_\b+_\b-_\bi_\bn_\bf_\bi_\bn_\bi_\bt_\by, _\bN_\ba_\bN) =
+infinity. This is intentional; it happens because h\bhy\byp\bpo\bot\bt(_\bi_\bn_\bf_\bi_\bn_\bi_\bt_\by, _\bv) =
+infinity for _\ba_\bl_\bl _\bv, finite or infinite. Hence h\bhy\byp\bpo\bot\bt(_\bi_\bn_\bf_\bi_\bn_\bi_\bt_\by, _\bv) is in-
dependent of _\bv. Unlike the reserved operand fault on a VAX, the IEEE _\bN_\ba_\bN
is designed to disappear when it turns out to be irrelevant, as it does
in h\bhy\byp\bpo\bot\bt(_\bi_\bn_\bf_\bi_\bn_\bi_\bt_\by, _\bN_\ba_\bN).
S\bSE\bEE\bE A\bAL\bLS\bSO\bO
math(3), sqrt(3)
H\bHI\bIS\bST\bTO\bOR\bRY\bY
Both a h\bhy\byp\bpo\bot\bt() function and a c\bca\bab\bbs\bs() function appeared in Version 7 AT&T
UNIX.
4th Berkeley Distribution June 4, 1993 1