1POW(3) Linux Programmer's Manual POW(3)
2
3
4
6 pow, powf, powl - power functions
7
9 #include <math.h>
10
11 double pow(double x, double y);
12 float powf(float x, float y);
13 long double powl(long double x, long double y);
14
15 Link with -lm.
16
17 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
18
19 powf(), powl():
20 _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
21 || /* Since glibc 2.19: */ _DEFAULT_SOURCE
22 || /* Glibc versions <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
23
25 These functions return the value of x raised to the power of y.
26
28 On success, these functions return the value of x to the power of y.
29
30 If x is a finite value less than 0, and y is a finite noninteger, a do‐
31 main error occurs, and a NaN is returned.
32
33 If the result overflows, a range error occurs, and the functions return
34 HUGE_VAL, HUGE_VALF, or HUGE_VALL, respectively, with the mathemati‐
35 cally correct sign.
36
37 If result underflows, and is not representable, a range error occurs,
38 and 0.0 is returned.
39
40 Except as specified below, if x or y is a NaN, the result is a NaN.
41
42 If x is +1, the result is 1.0 (even if y is a NaN).
43
44 If y is 0, the result is 1.0 (even if x is a NaN).
45
46 If x is +0 (-0), and y is an odd integer greater than 0, the result is
47 +0 (-0).
48
49 If x is 0, and y greater than 0 and not an odd integer, the result is
50 +0.
51
52 If x is -1, and y is positive infinity or negative infinity, the result
53 is 1.0.
54
55 If the absolute value of x is less than 1, and y is negative infinity,
56 the result is positive infinity.
57
58 If the absolute value of x is greater than 1, and y is negative infin‐
59 ity, the result is +0.
60
61 If the absolute value of x is less than 1, and y is positive infinity,
62 the result is +0.
63
64 If the absolute value of x is greater than 1, and y is positive infin‐
65 ity, the result is positive infinity.
66
67 If x is negative infinity, and y is an odd integer less than 0, the re‐
68 sult is -0.
69
70 If x is negative infinity, and y less than 0 and not an odd integer,
71 the result is +0.
72
73 If x is negative infinity, and y is an odd integer greater than 0, the
74 result is negative infinity.
75
76 If x is negative infinity, and y greater than 0 and not an odd integer,
77 the result is positive infinity.
78
79 If x is positive infinity, and y less than 0, the result is +0.
80
81 If x is positive infinity, and y greater than 0, the result is positive
82 infinity.
83
84 If x is +0 or -0, and y is an odd integer less than 0, a pole error oc‐
85 curs and HUGE_VAL, HUGE_VALF, or HUGE_VALL, is returned, with the same
86 sign as x.
87
88 If x is +0 or -0, and y is less than 0 and not an odd integer, a pole
89 error occurs and +HUGE_VAL, +HUGE_VALF, or +HUGE_VALL, is returned.
90
92 See math_error(7) for information on how to determine whether an error
93 has occurred when calling these functions.
94
95 The following errors can occur:
96
97 Domain error: x is negative, and y is a finite noninteger
98 errno is set to EDOM. An invalid floating-point exception
99 (FE_INVALID) is raised.
100
101 Pole error: x is zero, and y is negative
102 errno is set to ERANGE (but see BUGS). A divide-by-zero float‐
103 ing-point exception (FE_DIVBYZERO) is raised.
104
105 Range error: the result overflows
106 errno is set to ERANGE. An overflow floating-point exception
107 (FE_OVERFLOW) is raised.
108
109 Range error: the result underflows
110 errno is set to ERANGE. An underflow floating-point exception
111 (FE_UNDERFLOW) is raised.
112
114 For an explanation of the terms used in this section, see at‐
115 tributes(7).
116
117 ┌──────────────────────┬───────────────┬─────────┐
118 │Interface │ Attribute │ Value │
119 ├──────────────────────┼───────────────┼─────────┤
120 │pow(), powf(), powl() │ Thread safety │ MT-Safe │
121 └──────────────────────┴───────────────┴─────────┘
123 C99, POSIX.1-2001, POSIX.1-2008.
124
125 The variant returning double also conforms to SVr4, 4.3BSD, C89.
126
128 Historical bugs (now fixed)
129 Before glibc 2.28, on some architectures (e.g., x86-64) pow() may be
130 more than 10,000 times slower for some inputs than for other nearby in‐
131 puts. This affects only pow(), and not powf() nor powl(). This prob‐
132 lem was fixed in glibc 2.28.
133
134 A number of bugs in the glibc implementation of pow() were fixed in
135 glibc version 2.16.
136
137 In glibc 2.9 and earlier, when a pole error occurs, errno is set to
138 EDOM instead of the POSIX-mandated ERANGE. Since version 2.10, glibc
139 does the right thing.
140
141 In version 2.3.2 and earlier, when an overflow or underflow error oc‐
142 curs, glibc's pow() generates a bogus invalid floating-point exception
143 (FE_INVALID) in addition to the overflow or underflow exception.
144
146 cbrt(3), cpow(3), sqrt(3)
147
149 This page is part of release 5.10 of the Linux man-pages project. A
150 description of the project, information about reporting bugs, and the
151 latest version of this page, can be found at
152 https://www.kernel.org/doc/man-pages/.
153
154
155
156 2020-06-09 POW(3)