HYPOT(3POSIX)
π HYPOT(3POSIX) β ok bestie, let's talk triangles π
So this lil cutie lives in the POSIX Programmer's Manual (the 2017 edition, from IEEE / The Open Group, no big deal π ). Scroll to the very bottom for the whole copyright tea, but first:
πΈ PROLOG πΈ
This manual page is part of the POSIX Programmer's Manual. Heads up though, bestie: the Linux implementation of this interface may differ β so like, go consult the corresponding Linux manual page for the deets on Linux behavior. Orrrr the interface might not be implemented on Linux at all. It's giving mystery π.
β¨ NAME β¨
hypot, hypotf, hypotl β the Euclidean distance function, aka the "how far apart are these two things" girlies π¦
π SYNOPSIS π
#include <math.h>
double hypot(double x, double y);
float hypotf(float x, float y);
long double hypotl(long double x, long double y);
Look at them. Three sisters. All iconic. π
π DESCRIPTION π
Okay so first things first: the functionality described on this reference page is aligned with the ISO C standard. If anything here conflicts with the ISO C standard, that conflict is unintentional β this volume of POSIX.1β2017 defers to the ISO C standard. So like, ISO C is the main character here, we're just the group chat. π
These functions shall compute the value of the square root of x2+y2 β yes that's x-squared plus y-squared under a root, the whole Pythagorean moment β without undue overflow or underflow. She's careful. She's precise. She ate. π
Now, if you're an application and you wanna check for error situations (very valid of you), you should set errno to zero and call feclearexcept(FE_ALL_EXCEPT) before calling these functions. Then on return: if errno is non-zero, or if fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero, then an error has occurred. Vibe check failed, basically. π
π₯ RETURN VALUE π₯
Upon successful completion, these functions shall return the length of the hypotenuse of a right-angled triangle with sides of length x and y. Geometry class could NEVER. π
If the correct value would cause overflow, a range error shall occur, and hypot(), hypotf(), and hypotl() shall return the value of the macro HUGE_VAL, HUGE_VALF, and HUGE_VALL, respectively. Big number says "I cannot". π
- If
xoryis Β±Inf,+Infshall be returned β even if one ofxoryis NaN. Inf is that girl, she wins every argument. - If
xoryis NaN, and the other is not Β±Inf, aNaNshall be returned. Rude, but fair. - If both arguments are subnormal and the correct result is subnormal, a range error may occur, and the correct result shall be returned. She's doing her best okay π«Ά
π ERRORS π
These functions shall fail if:
- Range Error β The result overflows.
- If the integer expression
(math_errhandling & MATH_ERRNO)is non-zero, thenerrnoshall be set to[ERANGE]. - If the integer expression
(math_errhandling & MATH_ERREXCEPT)is non-zero, then the overflow floating-point exception shall be raised.
- If the integer expression
These functions may fail if:
- Range Error β The result underflows.
- If the integer expression
(math_errhandling & MATH_ERRNO)is non-zero, thenerrnoshall be set to[ERANGE]. - If the integer expression
(math_errhandling & MATH_ERREXCEPT)is non-zero, then the underflow floating-point exception shall be raised.
- If the integer expression
The following sections are informative β so like, the gossip portion of the page, not the binding contract π
π EXAMPLES π
See the EXAMPLES section in atan2(). That's it. That's the whole section. She's minimal, she's mysterious, go read your other bestie's page. π
π§ APPLICATION USAGE π§
hypot(x,y),hypot(y,x), andhypot(x, -y)are equivalent. Order doesn't matter, sign doesn't matter, she loves all her inputs equally πhypot(x, Β±0)is equivalent tofabs(x). Cute.- Underflow only happens when both
xandyare subnormal and the (inexact) result is also subnormal. Very specific. Very rare. Very demure. - These functions take precautions against overflow during intermediate steps of the computation. She's not gonna blow up mid-math, she plans ahead. β¨
- On error, the expressions
(math_errhandling & MATH_ERRNO)and(math_errhandling & MATH_ERREXCEPT)are independent of each other, but at least one of them must be non-zero. They're not texting each other, but they're both in the group chat. Periodt.
π¦ RATIONALE π¦
None.
Truly nothing to say. Silent. Stunning. π
β FUTURE DIRECTIONS β
None.
She's not changing. She's perfect the way she is. π
π SEE ALSO π
atan2()feclearexcept()fetestexcept()isnan()sqrt()
Also, from the Base Definitions volume of POSIX.1β2017: Section 4.20, Treatment of Error Conditions for Mathematical Functions, and <math.h>. Go read those too, bestie, iykyk π«Ά
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
okay that's the whole page bestie, mwah π
This one's brought to you by IEEE / The Open Group, dated 2017, and it's the HYPOT(3POSIX) page β go forth and compute your hypotenuses safely, no cap. πΈβ¨π
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms