1SQRT(P) POSIX Programmer's Manual SQRT(P)
2
3
4
6 sqrt, sqrtf, sqrtl - square root function
7
9 #include <math.h>
10
11 double sqrt(double x);
12 float sqrtf(float x);
13 long double sqrtl(long double x);
14
15
17 These functions shall compute the square root of their argument x,
18 sqrt(x).
19
20 An application wishing to check for error situations should set errno
21 to zero and call feclearexcept(FE_ALL_EXCEPT) before calling these
22 functions. On return, if errno is non-zero or fetestexcept(FE_INVALID
23 | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero, an error has
24 occurred.
25
27 Upon successful completion, these functions shall return the square
28 root of x.
29
30 For finite values of x < -0, a domain error shall occur, and either a
31 NaN (if supported), or an implementation-defined value shall be
32 returned.
33
34 If x is NaN, a NaN shall be returned.
35
36 If x is ±0 or +Inf, x shall be returned.
37
38 If x is -Inf, a domain error shall occur, and either a NaN (if sup‐
39 ported), or an implementation-defined value shall be returned.
40
42 These functions shall fail if:
43
44 Domain Error
45 The finite value of x is < -0, or x is -Inf.
46
47 If the integer expression (math_errhandling & MATH_ERRNO) is non-zero,
48 then errno shall be set to [EDOM]. If the integer expression
49 (math_errhandling & MATH_ERREXCEPT) is non-zero, then the invalid
50 floating-point exception shall be raised.
51
52
53 The following sections are informative.
54
56 Taking the Square Root of 9.0
57 #include <math.h>
58 ...
59 double x = 9.0;
60 double result;
61 ...
62 result = sqrt(x);
63
65 On error, the expressions (math_errhandling & MATH_ERRNO) and
66 (math_errhandling & MATH_ERREXCEPT) are independent of each other, but
67 at least one of them must be non-zero.
68
70 None.
71
73 None.
74
76 feclearexcept() , fetestexcept() , isnan() , the Base Definitions vol‐
77 ume of IEEE Std 1003.1-2001, Section 4.18, Treatment of Error Condi‐
78 tions for Mathematical Functions, <math.h>, <stdio.h>
79
81 Portions of this text are reprinted and reproduced in electronic form
82 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
83 -- Portable Operating System Interface (POSIX), The Open Group Base
84 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
85 Electrical and Electronics Engineers, Inc and The Open Group. In the
86 event of any discrepancy between this version and the original IEEE and
87 The Open Group Standard, the original IEEE and The Open Group Standard
88 is the referee document. The original Standard can be obtained online
89 at http://www.opengroup.org/unix/online.html .
90
91
92
93IEEE/The Open Group 2003 SQRT(P)