]>
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 | .\" |
93015253 | 5 | .\" %%%LICENSE_START(VERBATIM) |
fea681da MK |
6 | .\" Permission is granted to make and distribute verbatim copies of this |
7 | .\" manual provided the copyright notice and this permission notice are | |
8 | .\" preserved on all copies. | |
9 | .\" | |
10 | .\" Permission is granted to copy and distribute modified versions of this | |
11 | .\" manual under the conditions for verbatim copying, provided that the | |
12 | .\" entire resulting derived work is distributed under the terms of a | |
13 | .\" permission notice identical to this one. | |
c13182ef | 14 | .\" |
fea681da MK |
15 | .\" Since the Linux kernel and libraries are constantly changing, this |
16 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
17 | .\" responsibility for errors or omissions, or for damages resulting from | |
18 | .\" the use of the information contained herein. The author(s) may not | |
19 | .\" have taken the same level of care in the production of this manual, | |
20 | .\" which is licensed free of charge, as they might when working | |
21 | .\" professionally. | |
c13182ef | 22 | .\" |
fea681da MK |
23 | .\" Formatted or processed versions of this manual, if unaccompanied by |
24 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 25 | .\" %%%LICENSE_END |
fea681da MK |
26 | .\" |
27 | .\" References consulted: | |
28 | .\" Linux libc source code | |
29 | .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) | |
30 | .\" 386BSD man pages | |
31 | .\" Modified 1993-07-24 by Rik Faith (faith@cs.unc.edu) | |
32 | .\" Modified 1995-08-14 by Arnt Gulbrandsen <agulbra@troll.no> | |
33 | .\" Modified 2002-07-27 by Walter Harms | |
34 | .\" (walter.harms@informatik.uni-oldenburg.de) | |
4b8c67d9 | 35 | .TH POW 3 2017-09-15 "" "Linux Programmer's Manual" |
fea681da MK |
36 | .SH NAME |
37 | pow, powf, powl \- power functions | |
38 | .SH SYNOPSIS | |
39 | .nf | |
40 | .B #include <math.h> | |
68e4db0a | 41 | .PP |
fea681da | 42 | .BI "double pow(double " x ", double " y ); |
fea681da | 43 | .BI "float powf(float " x ", float " y ); |
fea681da MK |
44 | .BI "long double powl(long double " x ", long double " y ); |
45 | .fi | |
68e4db0a | 46 | .PP |
20c58d70 | 47 | Link with \fI\-lm\fP. |
68e4db0a | 48 | .PP |
207ce83e MK |
49 | .in -4n |
50 | Feature Test Macro Requirements for glibc (see | |
51 | .BR feature_test_macros (7)): | |
52 | .in | |
68e4db0a | 53 | .PP |
207ce83e MK |
54 | .ad l |
55 | .BR powf (), | |
56 | .BR powl (): | |
b90c43a8 | 57 | .RS 4 |
e9d91bcf MK |
58 | _ISOC99_SOURCE || _POSIX_C_SOURCE\ >=\ 200112L |
59 | || /* Since glibc 2.19: */ _DEFAULT_SOURCE | |
60 | || /* Glibc versions <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE | |
b90c43a8 MK |
61 | .RE |
62 | .ad | |
fea681da | 63 | .SH DESCRIPTION |
5600f73a | 64 | These functions return the value of |
022671eb MK |
65 | .I x |
66 | raised to the | |
67 | power of | |
68 | .IR y . | |
207ce83e MK |
69 | .SH RETURN VALUE |
70 | On success, these functions return the value of | |
71 | .I x | |
72 | to the power of | |
73 | .IR y . | |
847e0d88 | 74 | .PP |
207ce83e MK |
75 | If |
76 | .I x | |
77 | is a finite value less than 0, and | |
78 | .I y | |
24b74457 | 79 | is a finite noninteger, a domain error occurs, |
efe294cb | 80 | .\" The domain error is generated at least as far back as glibc 2.4 |
207ce83e | 81 | and a NaN is returned. |
847e0d88 | 82 | .PP |
207ce83e | 83 | If the result overflows, |
efe294cb MK |
84 | a range error occurs, |
85 | .\" The range error is generated at least as far back as glibc 2.4 | |
207ce83e MK |
86 | and the functions return |
87 | .BR HUGE_VAL , | |
88 | .BR HUGE_VALF , | |
89 | or | |
90 | .BR HUGE_VALL , | |
91 | respectively, with the mathematically correct sign. | |
847e0d88 | 92 | .PP |
207ce83e | 93 | If result underflows, and is not representable, |
efe294cb | 94 | a range error occurs, |
207ce83e MK |
95 | and 0.0 is returned. |
96 | .\" POSIX.1 does not specify the sign of the zero, | |
97 | .\" but http://sources.redhat.com/bugzilla/show_bug.cgi?id=2678 | |
98 | .\" points out that the zero has the wrong sign in some cases. | |
847e0d88 | 99 | .PP |
207ce83e MK |
100 | Except as specified below, if |
101 | .I x | |
102 | or | |
103 | .I y | |
104 | is a NaN, the result is a NaN. | |
847e0d88 | 105 | .PP |
207ce83e MK |
106 | If |
107 | .I x | |
108 | is +1, the result is 1.0 (even if | |
109 | .I y | |
110 | is a NaN). | |
847e0d88 | 111 | .PP |
207ce83e MK |
112 | If |
113 | .I y | |
114 | is 0, the result is 1.0 (even if | |
115 | .I x | |
116 | is a NaN). | |
847e0d88 | 117 | .PP |
207ce83e MK |
118 | If |
119 | .I x | |
120 | is +0 (\-0), | |
121 | and | |
122 | .I y | |
123 | is an odd integer greater than 0, | |
124 | the result is +0 (\-0). | |
847e0d88 | 125 | .PP |
207ce83e MK |
126 | If |
127 | .I x | |
128 | is 0, | |
129 | and | |
130 | .I y | |
131 | greater than 0 and not an odd integer, | |
132 | the result is +0. | |
847e0d88 | 133 | .PP |
207ce83e MK |
134 | If |
135 | .I x | |
136 | is \-1, | |
137 | and | |
138 | .I y | |
139 | is positive infinity or negative infinity, | |
140 | the result is 1.0. | |
847e0d88 | 141 | .PP |
207ce83e MK |
142 | If the absolute value of |
143 | .I x | |
144 | is less than 1, | |
145 | and | |
146 | .I y | |
147 | is negative infinity, | |
148 | the result is positive infinity. | |
847e0d88 | 149 | .PP |
207ce83e MK |
150 | If the absolute value of |
151 | .I x | |
152 | is greater than 1, | |
153 | and | |
154 | .I y | |
155 | is negative infinity, | |
156 | the result is +0. | |
847e0d88 | 157 | .PP |
207ce83e MK |
158 | If the absolute value of |
159 | .I x | |
160 | is less than 1, | |
161 | and | |
162 | .I y | |
163 | is positive infinity, | |
164 | the result is +0. | |
847e0d88 | 165 | .PP |
207ce83e MK |
166 | If the absolute value of |
167 | .I x | |
168 | is greater than 1, | |
169 | and | |
170 | .I y | |
171 | is positive infinity, | |
172 | the result is positive infinity. | |
847e0d88 | 173 | .PP |
207ce83e MK |
174 | If |
175 | .I x | |
176 | is negative infinity, | |
177 | and | |
178 | .I y | |
179 | is an odd integer less than 0, | |
180 | the result is \-0. | |
847e0d88 | 181 | .PP |
207ce83e MK |
182 | If |
183 | .I x | |
184 | is negative infinity, | |
185 | and | |
186 | .I y | |
187 | less than 0 and not an odd integer, | |
188 | the result is +0. | |
847e0d88 | 189 | .PP |
207ce83e MK |
190 | If |
191 | .I x | |
192 | is negative infinity, | |
193 | and | |
194 | .I y | |
195 | is an odd integer greater than 0, | |
196 | the result is negative infinity. | |
847e0d88 | 197 | .PP |
207ce83e MK |
198 | If |
199 | .I x | |
200 | is negative infinity, | |
201 | and | |
202 | .I y | |
203 | greater than 0 and not an odd integer, | |
204 | the result is positive infinity. | |
847e0d88 | 205 | .PP |
207ce83e MK |
206 | If |
207 | .I x | |
208 | is positive infinity, | |
209 | and | |
210 | .I y | |
211 | less than 0, | |
212 | the result is +0. | |
847e0d88 | 213 | .PP |
207ce83e MK |
214 | If |
215 | .I x | |
216 | is positive infinity, | |
217 | and | |
218 | .I y | |
219 | greater than 0, | |
220 | the result is positive infinity. | |
847e0d88 | 221 | .PP |
207ce83e MK |
222 | If |
223 | .I x | |
c3074d70 | 224 | is +0 or \-0, |
207ce83e MK |
225 | and |
226 | .I y | |
227 | is an odd integer less than 0, | |
efe294cb | 228 | a pole error occurs and |
207ce83e MK |
229 | .BR HUGE_VAL , |
230 | .BR HUGE_VALF , | |
231 | or | |
232 | .BR HUGE_VALL , | |
233 | is returned, | |
234 | with the same sign as | |
235 | .IR x . | |
847e0d88 | 236 | .PP |
207ce83e MK |
237 | If |
238 | .I x | |
c3074d70 | 239 | is +0 or \-0, |
207ce83e MK |
240 | and |
241 | .I y | |
242 | is less than 0 and not an odd integer, | |
efe294cb MK |
243 | a pole error occurs and |
244 | .\" The pole error is generated at least as far back as glibc 2.4 | |
207ce83e MK |
245 | .RB + HUGE_VAL , |
246 | .RB + HUGE_VALF , | |
247 | or | |
248 | .RB + HUGE_VALL , | |
249 | is returned. | |
fea681da | 250 | .SH ERRORS |
207ce83e MK |
251 | .\" FIXME . review status of this error |
252 | .\" longstanding bug report for glibc: | |
253 | .\" http://sources.redhat.com/bugzilla/show_bug.cgi?id=369 | |
254 | .\" For negative x, and -large and +large y, glibc 2.8 gives incorrect | |
255 | .\" results | |
256 | .\" pow(-0.5,-DBL_MAX)=nan | |
257 | .\" EDOM FE_INVALID nan; fail-errno fail-except fail-result; | |
258 | .\" FAIL (expected: range-error-overflow (ERANGE, FE_OVERFLOW); +INF) | |
385cf745 | 259 | .\" |
207ce83e MK |
260 | .\" pow(-1.5,-DBL_MAX)=nan |
261 | .\" EDOM FE_INVALID nan; fail-errno fail-except fail-result; | |
262 | .\" FAIL (expected: range-error-underflow (ERANGE, FE_UNDERFLOW); +0) | |
385cf745 | 263 | .\" |
207ce83e MK |
264 | .\" pow(-0.5,DBL_MAX)=nan |
265 | .\" EDOM FE_INVALID nan; fail-errno fail-except fail-result; | |
266 | .\" FAIL (expected: range-error-underflow (ERANGE, FE_UNDERFLOW); +0) | |
385cf745 | 267 | .\" |
207ce83e MK |
268 | .\" pow(-1.5,DBL_MAX)=nan |
269 | .\" EDOM FE_INVALID nan; fail-errno fail-except fail-result; | |
270 | .\" FAIL (expected: range-error-overflow (ERANGE, FE_OVERFLOW); +INF) | |
271 | See | |
272 | .BR math_error (7) | |
273 | for information on how to determine whether an error has occurred | |
274 | when calling these functions. | |
275 | .PP | |
276 | The following errors can occur: | |
fea681da | 277 | .TP |
24b74457 | 278 | Domain error: \fIx\fP is negative, and \fIy\fP is a finite noninteger |
207ce83e MK |
279 | .I errno |
280 | is set to | |
281 | .BR EDOM . | |
282 | An invalid floating-point exception | |
283 | .RB ( FE_INVALID ) | |
284 | is raised. | |
285 | .TP | |
286 | Pole error: \fIx\fP is zero, and \fIy\fP is negative | |
287 | .I errno | |
288 | is set to | |
385cf745 | 289 | .BR ERANGE |
207ce83e | 290 | (but see BUGS). |
207ce83e MK |
291 | A divide-by-zero floating-point exception |
292 | .RB ( FE_DIVBYZERO ) | |
293 | is raised. | |
294 | .TP | |
295 | Range error: the result overflows | |
296 | .I errno | |
297 | is set to | |
298 | .BR ERANGE . | |
299 | An overflow floating-point exception | |
300 | .RB ( FE_OVERFLOW ) | |
301 | is raised. | |
302 | .TP | |
303 | Range error: the result underflows | |
304 | .I errno | |
305 | is set to | |
306 | .BR ERANGE . | |
307 | An underflow floating-point exception | |
308 | .RB ( FE_UNDERFLOW ) | |
309 | is raised. | |
8e9d0d92 MS |
310 | .SH ATTRIBUTES |
311 | For an explanation of the terms used in this section, see | |
312 | .BR attributes (7). | |
313 | .TS | |
314 | allbox; | |
ee97f4e8 | 315 | lbw21 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 | |
47297adb | 324 | .SH CONFORMING TO |
9a74e018 | 325 | C99, POSIX.1-2001, POSIX.1-2008. |
847e0d88 | 326 | .PP |
207ce83e MK |
327 | The variant returning |
328 | .I double | |
329 | also conforms to | |
68e1685c | 330 | SVr4, 4.3BSD, C89. |
207ce83e | 331 | .SH BUGS |
285d20e3 MLI |
332 | On 64-bits, |
333 | .\" | |
334 | .\" https://sourceware.org/bugzilla/show_bug.cgi?id=13932 | |
335 | .BR pow () | |
ac5ba355 MK |
336 | may be more than 10,000 times slower for some (rare) inputs |
337 | than for other nearby inputs. | |
7908afea | 338 | This affects only |
285d20e3 | 339 | .BR pow (), |
ac5ba355 | 340 | and not |
285d20e3 MLI |
341 | .BR powf () |
342 | nor | |
343 | .BR powl (). | |
847e0d88 | 344 | .PP |
e20e01df | 345 | In glibc 2.9 and earlier, |
385cf745 | 346 | .\" |
e20e01df MK |
347 | .\" http://sources.redhat.com/bugzilla/show_bug.cgi?id=6776 |
348 | when a pole error occurs, | |
207ce83e MK |
349 | .I errno |
350 | is set to | |
e20e01df MK |
351 | .BR EDOM |
352 | instead of the POSIX-mandated | |
207ce83e | 353 | .BR ERANGE . |
e20e01df MK |
354 | Since version 2.10, |
355 | .\" or possibly 2.9, I haven't found the source code change | |
356 | .\" and I don't have a 2.9 system to test | |
357 | glibc does the right thing. | |
847e0d88 | 358 | .PP |
7ef981de MK |
359 | If |
360 | .I x | |
361 | is negative, | |
362 | then large negative or positive | |
363 | .I y | |
364 | values yield a NaN as the function result, with | |
365 | .I errno | |
366 | set to | |
367 | .BR EDOM , | |
368 | and an invalid | |
7e919b7a | 369 | .RB ( FE_INVALID ) |
7ef981de MK |
370 | floating-point exception. |
371 | For example, with | |
372 | .BR pow (), | |
373 | one sees this behavior when the absolute value of | |
374 | .I y | |
375 | is greater than about 9.223373e18. | |
376 | .\" see bug http://sources.redhat.com/bugzilla/show_bug.cgi?id=3866 | |
377 | .\" and http://sources.redhat.com/bugzilla/show_bug.cgi?id=369 | |
847e0d88 | 378 | .PP |
078dfbb0 | 379 | In version 2.3.2 and earlier, |
518e5c30 | 380 | .\" FIXME . Actually, 2.3.2 is the earliest test result I have; so yet |
078dfbb0 MK |
381 | .\" to confirm if this error occurs only in 2.3.2. |
382 | when an overflow or underflow error occurs, glibc's | |
383 | .BR pow () | |