From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/c/numeric%2Fmath%2Fsqrt.html | 76 ++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 devdocs/c/numeric%2Fmath%2Fsqrt.html (limited to 'devdocs/c/numeric%2Fmath%2Fsqrt.html') diff --git a/devdocs/c/numeric%2Fmath%2Fsqrt.html b/devdocs/c/numeric%2Fmath%2Fsqrt.html new file mode 100644 index 00000000..460db07c --- /dev/null +++ b/devdocs/c/numeric%2Fmath%2Fsqrt.html @@ -0,0 +1,76 @@ +

sqrt, sqrtf, sqrtl

Defined in header <math.h>
float       sqrtf( float arg );
+
(1) (since C99)
double      sqrt( double arg );
+
(2)
long double sqrtl( long double arg );
+
(3) (since C99)
Defined in header <tgmath.h>
#define sqrt( arg )
+
(4) (since C99)
+1-3) Computes square root of arg.
+4) Type-generic macro: If arg has type long double, sqrtl is called. Otherwise, if arg has integer type or the type double, sqrt is called. Otherwise, sqrtf is called. If arg is complex or imaginary, then the macro invokes the corresponding complex function (csqrtf, csqrt, csqrtl).

Parameters

+ +
arg - floating point value

Return value

If no errors occur, square root of arg (\({\small \sqrt{arg} }\)arg), is returned.

+

If a domain error occurs, an implementation-defined value is returned (NaN where supported).

+

If a range error occurs due to underflow, the correct result (after rounding) is returned.

+

Error handling

Errors are reported as specified in math_errhandling.

+

Domain error occurs if arg is less than zero.

+

If the implementation supports IEEE floating-point arithmetic (IEC 60559),

+

Notes

sqrt is required by the IEEE standard to be correctly rounded from the infinitely precise result. In particular, the exact result is produced if it can be represented in the floating-point type. The only other operations which require this are the arithmetic operators and the function fma. Other functions, including pow, are not so constrained.

+

Example

#include <stdio.h>
+#include <math.h>
+#include <errno.h>
+#include <fenv.h>
+ 
+#pragma STDC FENV_ACCESS ON
+ 
+int main(void)
+{
+    // normal use
+    printf("sqrt(100) = %f\n", sqrt(100));
+    printf("sqrt(2) = %f\n", sqrt(2));
+    printf("golden ratio = %f\n", (1+sqrt(5))/2);
+    // special values
+    printf("sqrt(-0) = %f\n", sqrt(-0.0));
+    // error handling
+    errno = 0; feclearexcept(FE_ALL_EXCEPT);
+    printf("sqrt(-1.0) = %f\n", sqrt(-1));
+    if(errno == EDOM) perror("    errno == EDOM");
+    if(fetestexcept(FE_INVALID)) puts("    FE_INVALID was raised");
+}

Possible output:

+
sqrt(100) = 10.000000
+sqrt(2) = 1.414214
+golden ratio = 1.618034
+sqrt(-0) = -0.000000
+sqrt(-1.0) = -nan
+    errno = EDOM: Numerical argument out of domain
+    FE_INVALID was raised

References

See also

+ + + + +
+
(C99)(C99)
computes a number raised to the given power (\(\small{x^y}\)xy)
(function)
+
(C99)(C99)(C99)
computes cube root (\(\small{\sqrt[3]{x} }\)3x)
(function)
+
(C99)(C99)(C99)
computes square root of the sum of the squares of two given numbers (\(\scriptsize{\sqrt{x^2+y^2} }\)x2+y2)
(function)
+
(C99)(C99)(C99)
computes the complex square root
(function)
C++ documentation for sqrt
+

+ © cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
+ https://en.cppreference.com/w/c/numeric/math/sqrt +

+
-- cgit v1.2.3