1HYPOT(3P) POSIX Programmer's Manual HYPOT(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 hypot, hypotf, hypotl — Euclidean distance function
13
15 #include <math.h>
16
17 double hypot(double x, double y);
18 float hypotf(float x, float y);
19 long double hypotl(long double x, long double y);
20
22 The functionality described on this reference page is aligned with the
23 ISO C standard. Any conflict between the requirements described here
24 and the ISO C standard is unintentional. This volume of POSIX.1‐2017
25 defers to the ISO C standard.
26
27 These functions shall compute the value of the square root of x2+y2
28 without undue overflow or underflow.
29
30 An application wishing to check for error situations should set errno
31 to zero and call feclearexcept(FE_ALL_EXCEPT) before calling these
32 functions. On return, if errno is non-zero or fetestexcept(FE_INVALID |
33 FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero, an error has
34 occurred.
35
37 Upon successful completion, these functions shall return the length of
38 the hypotenuse of a right-angled triangle with sides of length x and y.
39
40 If the correct value would cause overflow, a range error shall occur
41 and hypot(), hypotf(), and hypotl() shall return the value of the macro
42 HUGE_VAL, HUGE_VALF, and HUGE_VALL, respectively.
43
44 If x or y is ±Inf, +Inf shall be returned (even if one of x or y is
45 NaN).
46
47 If x or y is NaN, and the other is not ±Inf, a NaN shall be returned.
48
49 If both arguments are subnormal and the correct result is subnormal, a
50 range error may occur and the correct result shall be returned.
51
53 These functions shall fail if:
54
55 Range Error The result overflows.
56
57 If the integer expression (math_errhandling & MATH_ERRNO)
58 is non-zero, then errno shall be set to [ERANGE]. If the
59 integer expression (math_errhandling & MATH_ERREXCEPT) is
60 non-zero, then the overflow floating-point exception shall
61 be raised.
62
63 These functions may fail if:
64
65 Range Error The result underflows.
66
67 If the integer expression (math_errhandling & MATH_ERRNO)
68 is non-zero, then errno shall be set to [ERANGE]. If the
69 integer expression (math_errhandling & MATH_ERREXCEPT) is
70 non-zero, then the underflow floating-point exception shall
71 be raised.
72
73 The following sections are informative.
74
76 See the EXAMPLES section in atan2().
77
79 hypot(x,y), hypot(y,x), and hypot(x, -y) are equivalent.
80
81 hypot(x, ±0) is equivalent to fabs(x).
82
83 Underflow only happens when both x and y are subnormal and the (inex‐
84 act) result is also subnormal.
85
86 These functions take precautions against overflow during intermediate
87 steps of the computation.
88
89 On error, the expressions (math_errhandling & MATH_ERRNO) and
90 (math_errhandling & MATH_ERREXCEPT) are independent of each other, but
91 at least one of them must be non-zero.
92
94 None.
95
97 None.
98
100 atan2(), feclearexcept(), fetestexcept(), isnan(), sqrt()
101
102 The Base Definitions volume of POSIX.1‐2017, Section 4.20, Treatment of
103 Error Conditions for Mathematical Functions, <math.h>
104
106 Portions of this text are reprinted and reproduced in electronic form
107 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
108 table Operating System Interface (POSIX), The Open Group Base Specifi‐
109 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
110 Electrical and Electronics Engineers, Inc and The Open Group. In the
111 event of any discrepancy between this version and the original IEEE and
112 The Open Group Standard, the original IEEE and The Open Group Standard
113 is the referee document. The original Standard can be obtained online
114 at http://www.opengroup.org/unix/online.html .
115
116 Any typographical or formatting errors that appear in this page are
117 most likely to have been introduced during the conversion of the source
118 files to man page format. To report such errors, see https://www.ker‐
119 nel.org/doc/man-pages/reporting_bugs.html .
120
121
122
123IEEE/The Open Group 2017 HYPOT(3P)