hypot(3)

๐Ÿ’– hypot(3) โ€” the "how far is it tho" math bestie โœจ

okay so bestie, welcome to hypot(3) from the Library Functions Manual ๐ŸŽ€ this is the math-girlie page and honestly? she ate. no cap.


๐ŸŒธ NAME ๐ŸŒธ

hypot, hypotf, hypotl โ€” the Euclidean distance function ๐Ÿ’…

๐Ÿ“š LIBRARY ๐Ÿ“š

Math library (libm, -lm) โ€” yeah you gotta link the math lib, she doesn't come free ๐Ÿซถ

โœจ 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);

๐Ÿงš Feature Test Macro Requirements for glibc (iykyk, see feature_test_macros(7))

hypot():

_ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
    || _XOPEN_SOURCE
    || /* Since glibc 2.19: */ _DEFAULT_SOURCE
    || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE

hypotf(), hypotl():

_ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
    || /* Since glibc 2.19: */ _DEFAULT_SOURCE
    || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
bestie note: the difference between those two blocks is literally just the _XOPEN_SOURCE line and it's ONLY in hypot(). not me double-checking that five times ๐Ÿ™ˆ anyway, copy them exactly, they're load-bearing.

๐ŸŒˆ DESCRIPTION ๐ŸŒˆ

These functions return sqrt(x*x+y*y). ๐Ÿงฎโœจ

So basically: it's the length of the hypotenuse of a right-angled triangle whose sides are x and y long. OR, lowkey the same thing, it's the distance from the point (x,y) to the origin. same vibe, different outfit ๐Ÿ’…

The calculation is performed without undue overflow or underflow during the intermediate steps of the calculation. <- this is the whole reason hypot exists and isn't just you typing sqrt(x*x+y*y) by hand, bestie. she's careful. she's got main character energy. ๐Ÿ‘‘


๐Ÿฆ‹ RETURN VALUE ๐Ÿฆ‹

On success, these functions return the length of the hypotenuse of a right-angled triangle with sides of length x and y. easy, iconic, no notes โœจ

If x or y is an infinity, positive infinity is returned. โ™พ๏ธ

If x or y is a NaN, and the other argument is not an infinity, a NaN is returned. ๐Ÿซ 

If the result overflows, a range error occurs, and the functions return HUGE_VAL, HUGE_VALF, or HUGE_VALL, respectively. ๐Ÿ˜ญ

If both arguments are subnormal, and the result is subnormal, a range error occurs, and the correct result is returned. yes bestie, error AND correct answer at the same time, she's multitasking ๐Ÿ’€


๐Ÿ’€ ERRORS ๐Ÿ’€

See math_error(7) for the deets on how to figure out whether an error actually happened when you called these functions.

The following errors can occur:

  • Range error: result overflow โ€” errno is set to ERANGE. An overflow floating-point exception (FE_OVERFLOW) is raised. ๐Ÿ”ฅ
  • Range error: result underflow โ€” An underflow floating-point exception (FE_UNDERFLOW) is raised.
These functions do not set errno for this case. not me checking errno for no reason ๐Ÿ™ˆ

๐Ÿ‘‘ ATTRIBUTES ๐Ÿ‘‘

For an explanation of the terms used in this section, see attributes(7).

  • Interface: hypot(), hypotf(), hypotl()
  • Attribute: Thread safety
  • Value: MT-Safe ๐Ÿ”’ (she's safe to use across threads, periodt)

โญ STANDARDS โญ

C11, POSIX.1-2008.

๐ŸŽ€ HISTORY ๐ŸŽ€

C99, POSIX.1-2001.

The variant returning double also conforms to SVr4, 4.3BSD. yes she's old money AND new money ๐Ÿ’œ


๐Ÿ’– SEE ALSO ๐Ÿ’–

cabs(3), sqrt(3)


okay that's the whole page bestie, go forth and compute your distances the safe way ๐ŸŒธ๐Ÿฆ‹โœจ

ciao for now, and remember this was served fresh from Linux man-pages 6.20, dated 2026-02-08 โ€” hypot(3), signing off ๐Ÿ’…๐ŸŽ€๐Ÿ“

๐Ÿ“ฆ where this page comes from
  • arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • ๐Ÿ“œ the page's license: Linux-man-pages-copyleft
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms