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