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