]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/pow.3
Many pages: Fix style issues reported by `make lint-groff`
[thirdparty/man-pages.git] / man3 / pow.3
CommitLineData
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
17pow, powf, powl \- power functions
5d09fe3d
AC
18.SH LIBRARY
19Math 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
31Feature 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 43These functions return the value of
022671eb
MK
44.I x
45raised to the
46power of
47.IR y .
207ce83e
MK
48.SH RETURN VALUE
49On success, these functions return the value of
50.I x
51to the power of
52.IR y .
847e0d88 53.PP
207ce83e 54If the result overflows,
efe294cb
MK
55a range error occurs,
56.\" The range error is generated at least as far back as glibc 2.4
207ce83e
MK
57and the functions return
58.BR HUGE_VAL ,
59.BR HUGE_VALF ,
60or
61.BR HUGE_VALL ,
62respectively, with the mathematically correct sign.
847e0d88 63.PP
207ce83e 64If result underflows, and is not representable,
efe294cb 65a range error occurs,
5d89c3f3 66and 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
72If
73.I x
8bf30825
AC
74is +0 or \-0,
75and
207ce83e 76.I y
8bf30825
AC
77is an odd integer less than 0,
78a pole error occurs and
79.BR HUGE_VAL ,
80.BR HUGE_VALF ,
81or
82.BR HUGE_VALL ,
83is returned,
84with the same sign as
85.IR x .
847e0d88 86.PP
8bf30825 87.\" pow(\(+-0, <0 [[!odd]]) = HUGE_VAL*
207ce83e 88If
207ce83e 89.I x
8bf30825
AC
90is +0 or \-0,
91and
92.I y
93is less than 0 and not an odd integer,
94a 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 ,
98or
99.RB + HUGE_VALL ,
100is returned.
847e0d88 101.PP
8bf30825 102.\" pow(\(+-0, >0 [[odd]]) = \(+-0
207ce83e
MK
103If
104.I x
105is +0 (\-0),
106and
107.I y
108is an odd integer greater than 0,
109the result is +0 (\-0).
847e0d88 110.PP
8bf30825 111.\" pow(\(+-0, >0 [[!odd]]) = +0
207ce83e
MK
112If
113.I x
114is 0,
115and
116.I y
117greater than 0 and not an odd integer,
118the result is +0.
847e0d88 119.PP
8bf30825 120.\" pow(-1, \(+-INFINITY) = 1.0
207ce83e
MK
121If
122.I x
123is \-1,
124and
125.I y
126is positive infinity or negative infinity,
127the result is 1.0.
847e0d88 128.PP
8bf30825
AC
129.\" pow(+1, y) = 1.0
130If
131.I x
132is +1, the result is 1.0 (even if
133.I y
134is a NaN).
135.PP
136.\" pow(x, \(+-0) = 1.0
137If
138.I y
139is 0, the result is 1.0 (even if
140.I x
141is a NaN).
142.PP
143.\" pow(<0, y) = NaN
144If
145.I x
146is a finite value less than 0, and
147.I y
148is a finite noninteger, a domain error occurs,
149.\" The domain error is generated at least as far back as glibc 2.4
150and a NaN is returned.
151.PP
152.\" pow(|x|<1, -INFINITY) = INFINITY
207ce83e
MK
153If the absolute value of
154.I x
155is less than 1,
156and
157.I y
158is negative infinity,
159the result is positive infinity.
847e0d88 160.PP
8bf30825 161.\" pow(|x|>1, -INFINITY) = +0
207ce83e
MK
162If the absolute value of
163.I x
164is greater than 1,
165and
166.I y
167is negative infinity,
168the result is +0.
847e0d88 169.PP
8bf30825 170.\" pow(|x|<1, INFINITY) = +0
207ce83e
MK
171If the absolute value of
172.I x
173is less than 1,
174and
175.I y
176is positive infinity,
177the result is +0.
847e0d88 178.PP
8bf30825 179.\" pow(|x|>1, INFINITY) = INFINITY
207ce83e
MK
180If the absolute value of
181.I x
182is greater than 1,
183and
184.I y
185is positive infinity,
186the result is positive infinity.
847e0d88 187.PP
8bf30825 188.\" pow(-INFINITY, <0 [[odd]]) = -0
207ce83e
MK
189If
190.I x
191is negative infinity,
192and
193.I y
194is an odd integer less than 0,
195the result is \-0.
847e0d88 196.PP
8bf30825 197.\" pow(-INFINITY, <0 [[!odd]]) = +0
207ce83e
MK
198If
199.I x
200is negative infinity,
201and
202.I y
203less than 0 and not an odd integer,
204the result is +0.
847e0d88 205.PP
8bf30825 206.\" pow(-INFINITY, >0 [[odd]]) = -INFINITY
207ce83e
MK
207If
208.I x
209is negative infinity,
210and
211.I y
212is an odd integer greater than 0,
213the result is negative infinity.
847e0d88 214.PP
8bf30825 215.\" pow(-INFINITY, >0 [[!odd]]) = INFINITY
207ce83e
MK
216If
217.I x
218is negative infinity,
219and
220.I y
221greater than 0 and not an odd integer,
222the result is positive infinity.
847e0d88 223.PP
8bf30825 224.\" pow(INFINITY, <0) = +0
207ce83e
MK
225If
226.I x
227is positive infinity,
228and
229.I y
230less than 0,
231the result is +0.
847e0d88 232.PP
8bf30825 233.\" pow(INFINITY, >0) = INFINITY
207ce83e
MK
234If
235.I x
236is positive infinity,
237and
238.I y
239greater than 0,
240the result is positive infinity.
847e0d88 241.PP
8bf30825
AC
242.\" pow(NaN, y) or pow(x, NaN) = NaN
243Except as specified above, if
207ce83e 244.I x
207ce83e 245or
207ce83e 246.I y
8bf30825 247is 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)
269See
270.BR math_error (7)
271for information on how to determine whether an error has occurred
272when calling these functions.
273.PP
274The following errors can occur:
fea681da 275.TP
24b74457 276Domain error: \fIx\fP is negative, and \fIy\fP is a finite noninteger
207ce83e
MK
277.I errno
278is set to
279.BR EDOM .
280An invalid floating-point exception
281.RB ( FE_INVALID )
282is raised.
283.TP
284Pole error: \fIx\fP is zero, and \fIy\fP is negative
285.I errno
286is set to
1ae6b2c7 287.B ERANGE
207ce83e 288(but see BUGS).
207ce83e
MK
289A divide-by-zero floating-point exception
290.RB ( FE_DIVBYZERO )
291is raised.
292.TP
293Range error: the result overflows
294.I errno
295is set to
296.BR ERANGE .
297An overflow floating-point exception
298.RB ( FE_OVERFLOW )
299is raised.
300.TP
301Range error: the result underflows
302.I errno
303is set to
304.BR ERANGE .
305An underflow floating-point exception
306.RB ( FE_UNDERFLOW )
307is raised.
8e9d0d92
MS
308.SH ATTRIBUTES
309For 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
314allbox;
c466875e 315lbx lb lb
8e9d0d92
MS
316l l l.
317Interface Attribute Value
318T{
319.BR pow (),
320.BR powf (),
321.BR powl ()
322T} Thread safety MT-Safe
323.TE
c466875e
MK
324.hy
325.ad
326.sp 1
47297adb 327.SH CONFORMING TO
9a74e018 328C99, POSIX.1-2001, POSIX.1-2008.
847e0d88 329.PP
207ce83e
MK
330The variant returning
331.I double
332also conforms to
68e1685c 333SVr4, 4.3BSD, C89.
207ce83e 334.SH BUGS
e088313b 335.SS Historical bugs (now fixed)
427e4505 336Before glibc 2.28,
285d20e3 337.\" https://sourceware.org/bugzilla/show_bug.cgi?id=13932
427e4505 338on some architectures (e.g., x86-64)
285d20e3 339.BR pow ()
09ba59d4 340may be more than 10,000 times slower for some inputs
ac5ba355 341than for other nearby inputs.
7908afea 342This affects only
285d20e3 343.BR pow (),
ac5ba355 344and not
285d20e3
MLI
345.BR powf ()
346nor
347.BR powl ().
427e4505
MK
348This problem was fixed
349.\" commit c3d466cba1692708a19c6ff829d0386c83a0c6e5
350in glibc 2.28.
847e0d88 351.PP
831db5db
MK
352A number of bugs
353.\" http://sources.redhat.com/bugzilla/show_bug.cgi?id=3866
354in the glibc implementation of
355.BR pow ()
356were fixed in glibc version 2.16.
357.PP
e20e01df 358In glibc 2.9 and earlier,
385cf745 359.\"
e20e01df
MK
360.\" http://sources.redhat.com/bugzilla/show_bug.cgi?id=6776
361when a pole error occurs,
207ce83e
MK
362.I errno
363is set to
1ae6b2c7 364.B EDOM
e20e01df 365instead of the POSIX-mandated
207ce83e 366.BR ERANGE .
e20e01df
MK
367Since 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
370glibc does the right thing.
847e0d88 371.PP
078dfbb0 372In 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.
375when an overflow or underflow error occurs, glibc's
376.BR pow ()