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