]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/pow.3
prctl.2: Clarify the unsupported hardware case of EINVAL
[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.\"
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
37pow, 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 47Link with \fI\-lm\fP.
68e4db0a 48.PP
207ce83e
MK
49.in -4n
50Feature 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 64These functions return the value of
022671eb
MK
65.I x
66raised to the
67power of
68.IR y .
207ce83e
MK
69.SH RETURN VALUE
70On success, these functions return the value of
71.I x
72to the power of
73.IR y .
847e0d88 74.PP
207ce83e
MK
75If
76.I x
77is a finite value less than 0, and
78.I y
24b74457 79is a finite noninteger, a domain error occurs,
efe294cb 80.\" The domain error is generated at least as far back as glibc 2.4
207ce83e 81and a NaN is returned.
847e0d88 82.PP
207ce83e 83If the result overflows,
efe294cb
MK
84a range error occurs,
85.\" The range error is generated at least as far back as glibc 2.4
207ce83e
MK
86and the functions return
87.BR HUGE_VAL ,
88.BR HUGE_VALF ,
89or
90.BR HUGE_VALL ,
91respectively, with the mathematically correct sign.
847e0d88 92.PP
207ce83e 93If result underflows, and is not representable,
efe294cb 94a range error occurs,
207ce83e
MK
95and 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
100Except as specified below, if
101.I x
102or
103.I y
104is a NaN, the result is a NaN.
847e0d88 105.PP
207ce83e
MK
106If
107.I x
108is +1, the result is 1.0 (even if
109.I y
110is a NaN).
847e0d88 111.PP
207ce83e
MK
112If
113.I y
114is 0, the result is 1.0 (even if
115.I x
116is a NaN).
847e0d88 117.PP
207ce83e
MK
118If
119.I x
120is +0 (\-0),
121and
122.I y
123is an odd integer greater than 0,
124the result is +0 (\-0).
847e0d88 125.PP
207ce83e
MK
126If
127.I x
128is 0,
129and
130.I y
131greater than 0 and not an odd integer,
132the result is +0.
847e0d88 133.PP
207ce83e
MK
134If
135.I x
136is \-1,
137and
138.I y
139is positive infinity or negative infinity,
140the result is 1.0.
847e0d88 141.PP
207ce83e
MK
142If the absolute value of
143.I x
144is less than 1,
145and
146.I y
147is negative infinity,
148the result is positive infinity.
847e0d88 149.PP
207ce83e
MK
150If the absolute value of
151.I x
152is greater than 1,
153and
154.I y
155is negative infinity,
156the result is +0.
847e0d88 157.PP
207ce83e
MK
158If the absolute value of
159.I x
160is less than 1,
161and
162.I y
163is positive infinity,
164the result is +0.
847e0d88 165.PP
207ce83e
MK
166If the absolute value of
167.I x
168is greater than 1,
169and
170.I y
171is positive infinity,
172the result is positive infinity.
847e0d88 173.PP
207ce83e
MK
174If
175.I x
176is negative infinity,
177and
178.I y
179is an odd integer less than 0,
180the result is \-0.
847e0d88 181.PP
207ce83e
MK
182If
183.I x
184is negative infinity,
185and
186.I y
187less than 0 and not an odd integer,
188the result is +0.
847e0d88 189.PP
207ce83e
MK
190If
191.I x
192is negative infinity,
193and
194.I y
195is an odd integer greater than 0,
196the result is negative infinity.
847e0d88 197.PP
207ce83e
MK
198If
199.I x
200is negative infinity,
201and
202.I y
203greater than 0 and not an odd integer,
204the result is positive infinity.
847e0d88 205.PP
207ce83e
MK
206If
207.I x
208is positive infinity,
209and
210.I y
211less than 0,
212the result is +0.
847e0d88 213.PP
207ce83e
MK
214If
215.I x
216is positive infinity,
217and
218.I y
219greater than 0,
220the result is positive infinity.
847e0d88 221.PP
207ce83e
MK
222If
223.I x
c3074d70 224is +0 or \-0,
207ce83e
MK
225and
226.I y
227is an odd integer less than 0,
efe294cb 228a pole error occurs and
207ce83e
MK
229.BR HUGE_VAL ,
230.BR HUGE_VALF ,
231or
232.BR HUGE_VALL ,
233is returned,
234with the same sign as
235.IR x .
847e0d88 236.PP
207ce83e
MK
237If
238.I x
c3074d70 239is +0 or \-0,
207ce83e
MK
240and
241.I y
242is less than 0 and not an odd integer,
efe294cb
MK
243a 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 ,
247or
248.RB + HUGE_VALL ,
249is 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)
271See
272.BR math_error (7)
273for information on how to determine whether an error has occurred
274when calling these functions.
275.PP
276The following errors can occur:
fea681da 277.TP
24b74457 278Domain error: \fIx\fP is negative, and \fIy\fP is a finite noninteger
207ce83e
MK
279.I errno
280is set to
281.BR EDOM .
282An invalid floating-point exception
283.RB ( FE_INVALID )
284is raised.
285.TP
286Pole error: \fIx\fP is zero, and \fIy\fP is negative
287.I errno
288is set to
385cf745 289.BR ERANGE
207ce83e 290(but see BUGS).
207ce83e
MK
291A divide-by-zero floating-point exception
292.RB ( FE_DIVBYZERO )
293is raised.
294.TP
295Range error: the result overflows
296.I errno
297is set to
298.BR ERANGE .
299An overflow floating-point exception
300.RB ( FE_OVERFLOW )
301is raised.
302.TP
303Range error: the result underflows
304.I errno
305is set to
306.BR ERANGE .
307An underflow floating-point exception
308.RB ( FE_UNDERFLOW )
309is raised.
8e9d0d92
MS
310.SH ATTRIBUTES
311For an explanation of the terms used in this section, see
312.BR attributes (7).
313.TS
314allbox;
ee97f4e8 315lbw21 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
47297adb 324.SH CONFORMING TO
9a74e018 325C99, POSIX.1-2001, POSIX.1-2008.
847e0d88 326.PP
207ce83e
MK
327The variant returning
328.I double
329also conforms to
68e1685c 330SVr4, 4.3BSD, C89.
207ce83e 331.SH BUGS
285d20e3
MLI
332On 64-bits,
333.\"
334.\" https://sourceware.org/bugzilla/show_bug.cgi?id=13932
335.BR pow ()
ac5ba355
MK
336may be more than 10,000 times slower for some (rare) inputs
337than for other nearby inputs.
7908afea 338This affects only
285d20e3 339.BR pow (),
ac5ba355 340and not
285d20e3
MLI
341.BR powf ()
342nor
343.BR powl ().
847e0d88 344.PP
e20e01df 345In glibc 2.9 and earlier,
385cf745 346.\"
e20e01df
MK
347.\" http://sources.redhat.com/bugzilla/show_bug.cgi?id=6776
348when a pole error occurs,
207ce83e
MK
349.I errno
350is set to
e20e01df
MK
351.BR EDOM
352instead of the POSIX-mandated
207ce83e 353.BR ERANGE .
e20e01df
MK
354Since 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
357glibc does the right thing.
847e0d88 358.PP
7ef981de
MK
359If
360.I x
361is negative,
362then large negative or positive
363.I y
364values yield a NaN as the function result, with
365.I errno
366set to
367.BR EDOM ,
368and an invalid
7e919b7a 369.RB ( FE_INVALID )
7ef981de
MK
370floating-point exception.
371For example, with
372.BR pow (),
373one sees this behavior when the absolute value of
374.I y
375is 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 379In 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.
382when an overflow or underflow error occurs, glibc's
383.BR pow ()