]>
Commit | Line | Data |
---|---|---|
fea681da | 1 | .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) |
207ce83e MK |
2 | .\" and Copyright 2008, Linux Foundation, written by Michael Kerrisk |
3 | .\" <mtk.manpages@gmail.com> | |
fea681da | 4 | .\" |
5fbde956 | 5 | .\" SPDX-License-Identifier: Linux-man-pages-copyleft |
fea681da MK |
6 | .\" |
7 | .\" References consulted: | |
8 | .\" Linux libc source code | |
9 | .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) | |
10 | .\" 386BSD man pages | |
11 | .\" Modified 1993-07-24 by Rik Faith (faith@cs.unc.edu) | |
12 | .\" Modified 1995-08-14 by Arnt Gulbrandsen <agulbra@troll.no> | |
13 | .\" Modified 2002-07-27 by Walter Harms | |
14 | .\" (walter.harms@informatik.uni-oldenburg.de) | |
1ae6b2c7 | 15 | .TH POW 3 2021-03-22 GNU "Linux Programmer's Manual" |
fea681da MK |
16 | .SH NAME |
17 | pow, powf, powl \- power functions | |
5d09fe3d AC |
18 | .SH LIBRARY |
19 | Math library | |
8fc3b2cf | 20 | .RI ( libm ", " \-lm ) |
fea681da MK |
21 | .SH SYNOPSIS |
22 | .nf | |
23 | .B #include <math.h> | |
68e4db0a | 24 | .PP |
fea681da | 25 | .BI "double pow(double " x ", double " y ); |
fea681da | 26 | .BI "float powf(float " x ", float " y ); |
fea681da MK |
27 | .BI "long double powl(long double " x ", long double " y ); |
28 | .fi | |
68e4db0a | 29 | .PP |
d39ad78f | 30 | .RS -4 |
207ce83e MK |
31 | Feature Test Macro Requirements for glibc (see |
32 | .BR feature_test_macros (7)): | |
d39ad78f | 33 | .RE |
68e4db0a | 34 | .PP |
207ce83e MK |
35 | .BR powf (), |
36 | .BR powl (): | |
9d2adbae | 37 | .nf |
5c10d2c5 | 38 | _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L |
9d2adbae MK |
39 | || /* Since glibc 2.19: */ _DEFAULT_SOURCE |
40 | || /* Glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE | |
41 | .fi | |
fea681da | 42 | .SH DESCRIPTION |
5600f73a | 43 | These functions return the value of |
022671eb MK |
44 | .I x |
45 | raised to the | |
46 | power of | |
47 | .IR y . | |
207ce83e MK |
48 | .SH RETURN VALUE |
49 | On success, these functions return the value of | |
50 | .I x | |
51 | to the power of | |
52 | .IR y . | |
847e0d88 | 53 | .PP |
207ce83e | 54 | If the result overflows, |
efe294cb MK |
55 | a range error occurs, |
56 | .\" The range error is generated at least as far back as glibc 2.4 | |
207ce83e MK |
57 | and the functions return |
58 | .BR HUGE_VAL , | |
59 | .BR HUGE_VALF , | |
60 | or | |
61 | .BR HUGE_VALL , | |
62 | respectively, with the mathematically correct sign. | |
847e0d88 | 63 | .PP |
207ce83e | 64 | If result underflows, and is not representable, |
efe294cb | 65 | a range error occurs, |
5d89c3f3 | 66 | and 0.0 with the appropriate sign is returned. |
207ce83e MK |
67 | .\" POSIX.1 does not specify the sign of the zero, |
68 | .\" but http://sources.redhat.com/bugzilla/show_bug.cgi?id=2678 | |
69 | .\" points out that the zero has the wrong sign in some cases. | |
847e0d88 | 70 | .PP |
8bf30825 | 71 | .\" pow(\(+-0, <0 [[odd]]) = HUGE_VAL* |
207ce83e MK |
72 | If |
73 | .I x | |
8bf30825 AC |
74 | is +0 or \-0, |
75 | and | |
207ce83e | 76 | .I y |
8bf30825 AC |
77 | is an odd integer less than 0, |
78 | a pole error occurs and | |
79 | .BR HUGE_VAL , | |
80 | .BR HUGE_VALF , | |
81 | or | |
82 | .BR HUGE_VALL , | |
83 | is returned, | |
84 | with the same sign as | |
85 | .IR x . | |
847e0d88 | 86 | .PP |
8bf30825 | 87 | .\" pow(\(+-0, <0 [[!odd]]) = HUGE_VAL* |
207ce83e | 88 | If |
207ce83e | 89 | .I x |
8bf30825 AC |
90 | is +0 or \-0, |
91 | and | |
92 | .I y | |
93 | is less than 0 and not an odd integer, | |
94 | a pole error occurs and | |
95 | .\" The pole error is generated at least as far back as glibc 2.4 | |
96 | .RB + HUGE_VAL , | |
97 | .RB + HUGE_VALF , | |
98 | or | |
99 | .RB + HUGE_VALL , | |
100 | is returned. | |
847e0d88 | 101 | .PP |
8bf30825 | 102 | .\" pow(\(+-0, >0 [[odd]]) = \(+-0 |
207ce83e MK |
103 | If |
104 | .I x | |
105 | is +0 (\-0), | |
106 | and | |
107 | .I y | |
108 | is an odd integer greater than 0, | |
109 | the result is +0 (\-0). | |
847e0d88 | 110 | .PP |
8bf30825 | 111 | .\" pow(\(+-0, >0 [[!odd]]) = +0 |
207ce83e MK |
112 | If |
113 | .I x | |
114 | is 0, | |
115 | and | |
116 | .I y | |
117 | greater than 0 and not an odd integer, | |
118 | the result is +0. | |
847e0d88 | 119 | .PP |
8bf30825 | 120 | .\" pow(-1, \(+-INFINITY) = 1.0 |
207ce83e MK |
121 | If |
122 | .I x | |
123 | is \-1, | |
124 | and | |
125 | .I y | |
126 | is positive infinity or negative infinity, | |
127 | the result is 1.0. | |
847e0d88 | 128 | .PP |
8bf30825 AC |
129 | .\" pow(+1, y) = 1.0 |
130 | If | |
131 | .I x | |
132 | is +1, the result is 1.0 (even if | |
133 | .I y | |
134 | is a NaN). | |
135 | .PP | |
136 | .\" pow(x, \(+-0) = 1.0 | |
137 | If | |
138 | .I y | |
139 | is 0, the result is 1.0 (even if | |
140 | .I x | |
141 | is a NaN). | |
142 | .PP | |
143 | .\" pow(<0, y) = NaN | |
144 | If | |
145 | .I x | |
146 | is a finite value less than 0, and | |
147 | .I y | |
148 | is a finite noninteger, a domain error occurs, | |
149 | .\" The domain error is generated at least as far back as glibc 2.4 | |
150 | and a NaN is returned. | |
151 | .PP | |
152 | .\" pow(|x|<1, -INFINITY) = INFINITY | |
207ce83e MK |
153 | If the absolute value of |
154 | .I x | |
155 | is less than 1, | |
156 | and | |
157 | .I y | |
158 | is negative infinity, | |
159 | the result is positive infinity. | |
847e0d88 | 160 | .PP |
8bf30825 | 161 | .\" pow(|x|>1, -INFINITY) = +0 |
207ce83e MK |
162 | If the absolute value of |
163 | .I x | |
164 | is greater than 1, | |
165 | and | |
166 | .I y | |
167 | is negative infinity, | |
168 | the result is +0. | |
847e0d88 | 169 | .PP |
8bf30825 | 170 | .\" pow(|x|<1, INFINITY) = +0 |
207ce83e MK |
171 | If the absolute value of |
172 | .I x | |
173 | is less than 1, | |
174 | and | |
175 | .I y | |
176 | is positive infinity, | |
177 | the result is +0. | |
847e0d88 | 178 | .PP |
8bf30825 | 179 | .\" pow(|x|>1, INFINITY) = INFINITY |
207ce83e MK |
180 | If the absolute value of |
181 | .I x | |
182 | is greater than 1, | |
183 | and | |
184 | .I y | |
185 | is positive infinity, | |
186 | the result is positive infinity. | |
847e0d88 | 187 | .PP |
8bf30825 | 188 | .\" pow(-INFINITY, <0 [[odd]]) = -0 |
207ce83e MK |
189 | If |
190 | .I x | |
191 | is negative infinity, | |
192 | and | |
193 | .I y | |
194 | is an odd integer less than 0, | |
195 | the result is \-0. | |
847e0d88 | 196 | .PP |
8bf30825 | 197 | .\" pow(-INFINITY, <0 [[!odd]]) = +0 |
207ce83e MK |
198 | If |
199 | .I x | |
200 | is negative infinity, | |
201 | and | |
202 | .I y | |
203 | less than 0 and not an odd integer, | |
204 | the result is +0. | |
847e0d88 | 205 | .PP |
8bf30825 | 206 | .\" pow(-INFINITY, >0 [[odd]]) = -INFINITY |
207ce83e MK |
207 | If |
208 | .I x | |
209 | is negative infinity, | |
210 | and | |
211 | .I y | |
212 | is an odd integer greater than 0, | |
213 | the result is negative infinity. | |
847e0d88 | 214 | .PP |
8bf30825 | 215 | .\" pow(-INFINITY, >0 [[!odd]]) = INFINITY |
207ce83e MK |
216 | If |
217 | .I x | |
218 | is negative infinity, | |
219 | and | |
220 | .I y | |
221 | greater than 0 and not an odd integer, | |
222 | the result is positive infinity. | |
847e0d88 | 223 | .PP |
8bf30825 | 224 | .\" pow(INFINITY, <0) = +0 |
207ce83e MK |
225 | If |
226 | .I x | |
227 | is positive infinity, | |
228 | and | |
229 | .I y | |
230 | less than 0, | |
231 | the result is +0. | |
847e0d88 | 232 | .PP |
8bf30825 | 233 | .\" pow(INFINITY, >0) = INFINITY |
207ce83e MK |
234 | If |
235 | .I x | |
236 | is positive infinity, | |
237 | and | |
238 | .I y | |
239 | greater than 0, | |
240 | the result is positive infinity. | |
847e0d88 | 241 | .PP |
8bf30825 AC |
242 | .\" pow(NaN, y) or pow(x, NaN) = NaN |
243 | Except as specified above, if | |
207ce83e | 244 | .I x |
207ce83e | 245 | or |
207ce83e | 246 | .I y |
8bf30825 | 247 | is a NaN, the result is a NaN. |
fea681da | 248 | .SH ERRORS |
207ce83e MK |
249 | .\" FIXME . review status of this error |
250 | .\" longstanding bug report for glibc: | |
251 | .\" http://sources.redhat.com/bugzilla/show_bug.cgi?id=369 | |
252 | .\" For negative x, and -large and +large y, glibc 2.8 gives incorrect | |
253 | .\" results | |
254 | .\" pow(-0.5,-DBL_MAX)=nan | |
255 | .\" EDOM FE_INVALID nan; fail-errno fail-except fail-result; | |
256 | .\" FAIL (expected: range-error-overflow (ERANGE, FE_OVERFLOW); +INF) | |
385cf745 | 257 | .\" |
207ce83e MK |
258 | .\" pow(-1.5,-DBL_MAX)=nan |
259 | .\" EDOM FE_INVALID nan; fail-errno fail-except fail-result; | |
260 | .\" FAIL (expected: range-error-underflow (ERANGE, FE_UNDERFLOW); +0) | |
385cf745 | 261 | .\" |
207ce83e MK |
262 | .\" pow(-0.5,DBL_MAX)=nan |
263 | .\" EDOM FE_INVALID nan; fail-errno fail-except fail-result; | |
264 | .\" FAIL (expected: range-error-underflow (ERANGE, FE_UNDERFLOW); +0) | |
385cf745 | 265 | .\" |
207ce83e MK |
266 | .\" pow(-1.5,DBL_MAX)=nan |
267 | .\" EDOM FE_INVALID nan; fail-errno fail-except fail-result; | |
268 | .\" FAIL (expected: range-error-overflow (ERANGE, FE_OVERFLOW); +INF) | |
269 | See | |
270 | .BR math_error (7) | |
271 | for information on how to determine whether an error has occurred | |
272 | when calling these functions. | |
273 | .PP | |
274 | The following errors can occur: | |
fea681da | 275 | .TP |
24b74457 | 276 | Domain error: \fIx\fP is negative, and \fIy\fP is a finite noninteger |
207ce83e MK |
277 | .I errno |
278 | is set to | |
279 | .BR EDOM . | |
280 | An invalid floating-point exception | |
281 | .RB ( FE_INVALID ) | |
282 | is raised. | |
283 | .TP | |
284 | Pole error: \fIx\fP is zero, and \fIy\fP is negative | |
285 | .I errno | |
286 | is set to | |
1ae6b2c7 | 287 | .B ERANGE |
207ce83e | 288 | (but see BUGS). |
207ce83e MK |
289 | A divide-by-zero floating-point exception |
290 | .RB ( FE_DIVBYZERO ) | |
291 | is raised. | |
292 | .TP | |
293 | Range error: the result overflows | |
294 | .I errno | |
295 | is set to | |
296 | .BR ERANGE . | |
297 | An overflow floating-point exception | |
298 | .RB ( FE_OVERFLOW ) | |
299 | is raised. | |
300 | .TP | |
301 | Range error: the result underflows | |
302 | .I errno | |
303 | is set to | |
304 | .BR ERANGE . | |
305 | An underflow floating-point exception | |
306 | .RB ( FE_UNDERFLOW ) | |
307 | is raised. | |
8e9d0d92 MS |
308 | .SH ATTRIBUTES |
309 | For an explanation of the terms used in this section, see | |
310 | .BR attributes (7). | |
c466875e MK |
311 | .ad l |
312 | .nh | |
8e9d0d92 MS |
313 | .TS |
314 | allbox; | |
c466875e | 315 | lbx lb lb |
8e9d0d92 MS |
316 | l l l. |
317 | Interface Attribute Value | |
318 | T{ | |
319 | .BR pow (), | |
320 | .BR powf (), | |
321 | .BR powl () | |
322 | T} Thread safety MT-Safe | |
323 | .TE | |
c466875e MK |
324 | .hy |
325 | .ad | |
326 | .sp 1 | |
47297adb | 327 | .SH CONFORMING TO |
9a74e018 | 328 | C99, POSIX.1-2001, POSIX.1-2008. |
847e0d88 | 329 | .PP |
207ce83e MK |
330 | The variant returning |
331 | .I double | |
332 | also conforms to | |
68e1685c | 333 | SVr4, 4.3BSD, C89. |
207ce83e | 334 | .SH BUGS |
e088313b | 335 | .SS Historical bugs (now fixed) |
427e4505 | 336 | Before glibc 2.28, |
285d20e3 | 337 | .\" https://sourceware.org/bugzilla/show_bug.cgi?id=13932 |
427e4505 | 338 | on some architectures (e.g., x86-64) |
285d20e3 | 339 | .BR pow () |
09ba59d4 | 340 | may be more than 10,000 times slower for some inputs |
ac5ba355 | 341 | than for other nearby inputs. |
7908afea | 342 | This affects only |
285d20e3 | 343 | .BR pow (), |
ac5ba355 | 344 | and not |
285d20e3 MLI |
345 | .BR powf () |
346 | nor | |
347 | .BR powl (). | |
427e4505 MK |
348 | This problem was fixed |
349 | .\" commit c3d466cba1692708a19c6ff829d0386c83a0c6e5 | |
350 | in glibc 2.28. | |
847e0d88 | 351 | .PP |
831db5db MK |
352 | A number of bugs |
353 | .\" http://sources.redhat.com/bugzilla/show_bug.cgi?id=3866 | |
354 | in the glibc implementation of | |
355 | .BR pow () | |
356 | were fixed in glibc version 2.16. | |
357 | .PP | |
e20e01df | 358 | In glibc 2.9 and earlier, |
385cf745 | 359 | .\" |
e20e01df MK |
360 | .\" http://sources.redhat.com/bugzilla/show_bug.cgi?id=6776 |
361 | when a pole error occurs, | |
207ce83e MK |
362 | .I errno |
363 | is set to | |
1ae6b2c7 | 364 | .B EDOM |
e20e01df | 365 | instead of the POSIX-mandated |
207ce83e | 366 | .BR ERANGE . |
e20e01df MK |
367 | Since version 2.10, |
368 | .\" or possibly 2.9, I haven't found the source code change | |
369 | .\" and I don't have a 2.9 system to test | |
370 | glibc does the right thing. | |
847e0d88 | 371 | .PP |
078dfbb0 | 372 | In version 2.3.2 and earlier, |
247a2afa | 373 | .\" Actually, 2.3.2 is the earliest test result I have; so yet |
078dfbb0 MK |
374 | .\" to confirm if this error occurs only in 2.3.2. |
375 | when an overflow or underflow error occurs, glibc's | |
376 | .BR pow () | |