SQRT(3P)
π¦ SQRT(3P) β bestie edition π¦
okay so first things first: this is SQRT(3P), and she lives in the POSIX Programmer's Manual β¨ (that's the <pink>3P</pink> part, iykyk).
πΈ PROLOG πΈ
so before we even get into it β heads up, this page is part of the POSIX Programmer's Manual π. The Linux implementation of this interface may differ (like, go check the corresponding Linux manual page for the deets on Linux behavior, fr), or honestly the interface may not even be implemented on Linux at all. Not me warning you in advance π.
π NAME π
sqrt, sqrtf, sqrtl β square root function. that's it, that's the girl. π
β¨ SYNOPSIS β¨
#include <math.h>
double sqrt(double x);
float sqrtf(float x);
long double sqrtl(long double x);
three icons, one job. π
π DESCRIPTION π
The functionality described on this reference page is aligned with the ISO C standard. And like, if there's any conflict between what's written here and the ISO C standard? That's unintentional bestie, no cap. This volume of POSIX.1β2017 defers to the ISO C standard. periodt. π
These functions shall compute the square root of their argument x, βx. literally the whole vibe. β¨
An application wishing to check for error situations should set errno to zero and call feclearexcept(FE_ALL_EXCEPT) before calling these functions. On return, if errno is non-zero or fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero, an error has occurred. so like, set up your little vibe check before you call, okay? π
π«Ά RETURN VALUE π«Ά
Upon successful completion, these functions shall return the square root of x. slay. π
For finite values of x < -0, a domain error shall occur, and either a NaN (if supported), or an implementation-defined value shall be returned. so yeah, negative inputs are giving chaos energy π.
If x is NaN, a NaN shall be returned.
If x is Β±0 or +Inf, x shall be returned. (yes bestie, she hands you back exactly what you gave her π)
If x is -Inf, a domain error shall occur, and a NaN shall be returned.
π ERRORS π
These functions shall fail if:
Domain Error π¨
The finite value of x is < -0, or x is -Inf. like, don't do that. π
If the integer expression (math_errhandling & MATH_ERRNO) is non-zero, then errno shall be set to [EDOM]. If the integer expression (math_errhandling & MATH_ERREXCEPT) is non-zero, then the invalid floating-point exception shall be raised.
The following sections are informative.
πΈ EXAMPLES πΈ
Taking the Square Root of 9.0 β
#include <math.h>
...
double x = 9.0;
double result;
...
result = sqrt(x);
look at her go π§ (spoiler: result is 3.0, but that's just math being math, the page didn't say it, so don't @ me π
)
π APPLICATION USAGE π
On error, the expressions (math_errhandling & MATH_ERRNO) and (math_errhandling & MATH_ERREXCEPT) are independent of each other β like two besties living their own lives π β but at least one of them must be non-zero. one of them has to show up to the party, fr fr.
π RATIONALE π
None.
(genuinely nothing. she said no thoughts, head empty π¦)
β FUTURE DIRECTIONS β
None.
(no plans, no drama, just vibes β¨)
π SEE ALSO π
feclearexcept()fetestexcept()isnan()
The Base Definitions volume of POSIX.1β2017, Section 4.20, Treatment of Error Conditions for Mathematical Functions, <math.h>, <stdio.h>
π 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 .
and that's the whole page bestie π«Ά this one's brought to you by IEEE/The Open Group, 2017 β mwah, take care of her, she's iconic π β¨πΈ
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- 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-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms