float sqrtf( float arg );
(1) (since C99)double sqrt( double arg );
(2)long double sqrtl( long double arg );
(3) (since C99)#define sqrt( arg )
(4) (since C99)1-3) Computes square root of arg.
4)Type-generic macro: If
arghas type
long double,
sqrtl
is called. Otherwise, if
arghas integer type or the type
double,
sqrt
is called. Otherwise,
sqrtf
is called. If
argis complex or imaginary, then the macro invokes the corresponding complex function (
csqrtf,
csqrt,
csqrtl).
[edit] Parameters arg - floating-point value [edit] Return valueIf 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.
[edit] Error handlingErrors 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),
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.
#include <errno.h> #include <fenv.h> #include <math.h> #include <stdio.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[edit] References
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4