1HYPOT(P) POSIX Programmer's Manual HYPOT(P)
2
3
4
6 hypot, hypotf, hypotl - Euclidean distance function
7
9 #include <math.h>
10
11 double hypot(double x, double y);
12 float hypotf(float x, float y);
13 long double hypotl(long double x, long double y);
14
15
17 These functions shall compute the value of the square root of x**2+
18 y**2 without undue overflow or underflow.
19
20 An application wishing to check for error situations should set errno
21 to zero and call feclearexcept(FE_ALL_EXCEPT) before calling these
22 functions. On return, if errno is non-zero or fetestexcept(FE_INVALID
23 | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero, an error has
24 occurred.
25
27 Upon successful completion, these functions shall return the length of
28 the hypotenuse of a right-angled triangle with sides of length x and y.
29
30 If the correct value would cause overflow, a range error shall occur
31 and hypot(), hypotf(), and hypotl() shall return the value of the macro
32 HUGE_VAL, HUGE_VALF, and HUGE_VALL, respectively.
33
34 If x or y is ±Inf, +Inf shall be returned (even if one of x or y is
35 NaN).
36
37 If x or y is NaN, and the other is not ±Inf, a NaN shall be returned.
38
39 If both arguments are subnormal and the correct result is subnormal, a
40 range error may occur and the correct result is returned.
41
43 These functions shall fail if:
44
45 Range Error
46 The result overflows.
47
48 If the integer expression (math_errhandling & MATH_ERRNO) is non-zero,
49 then errno shall be set to [ERANGE]. If the integer expression
50 (math_errhandling & MATH_ERREXCEPT) is non-zero, then the overflow
51 floating-point exception shall be raised.
52
53
54 These functions may fail if:
55
56 Range Error
57 The result underflows.
58
59 If the integer expression (math_errhandling & MATH_ERRNO) is non-zero,
60 then errno shall be set to [ERANGE]. If the integer expression
61 (math_errhandling & MATH_ERREXCEPT) is non-zero, then the underflow
62 floating-point exception shall be raised.
63
64
65 The following sections are informative.
66
68 None.
69
71 hypot(x,y), hypot(y,x), and hypot(x, -y) are equivalent.
72
73 hypot(x, ±0) is equivalent to fabs(x).
74
75 Underflow only happens when both x and y are subnormal and the (inex‐
76 act) result is also subnormal.
77
78 These functions take precautions against overflow during intermediate
79 steps of the computation.
80
81 On error, the expressions (math_errhandling & MATH_ERRNO) and
82 (math_errhandling & MATH_ERREXCEPT) are independent of each other, but
83 at least one of them must be non-zero.
84
86 None.
87
89 None.
90
92 feclearexcept() , fetestexcept() , isnan() , sqrt() , the Base Defini‐
93 tions volume of IEEE Std 1003.1-2001, Section 4.18, Treatment of Error
94 Conditions for Mathematical Functions, <math.h>
95
97 Portions of this text are reprinted and reproduced in electronic form
98 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
99 -- Portable Operating System Interface (POSIX), The Open Group Base
100 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
101 Electrical and Electronics Engineers, Inc and The Open Group. In the
102 event of any discrepancy between this version and the original IEEE and
103 The Open Group Standard, the original IEEE and The Open Group Standard
104 is the referee document. The original Standard can be obtained online
105 at http://www.opengroup.org/unix/online.html .
106
107
108
109IEEE/The Open Group 2003 HYPOT(P)