xref: /freebsd/lib/msun/man/exp.3 (revision 4f29da19bd44f0e99f021510460a81bf754c21d2)
1.\" Copyright (c) 1985, 1991 Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\"    must display the following acknowledgement:
14.\"	This product includes software developed by the University of
15.\"	California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\"     from: @(#)exp.3	6.12 (Berkeley) 7/31/91
33.\" $FreeBSD$
34.\"
35.Dd April 5, 2005
36.Dt EXP 3
37.Os
38.Sh NAME
39.Nm exp ,
40.Nm expf ,
41.\" The sorting error is intentional.  exp and expf should be adjacent.
42.Nm exp2 ,
43.Nm exp2f ,
44.Nm expm1 ,
45.Nm expm1f ,
46.Nm log ,
47.Nm logf ,
48.Nm log10 ,
49.Nm log10f ,
50.Nm log1p ,
51.Nm log1pf ,
52.Nm pow ,
53.Nm powf
54.Nd exponential, logarithm, power functions
55.Sh LIBRARY
56.Lb libm
57.Sh SYNOPSIS
58.In math.h
59.Ft double
60.Fn exp "double x"
61.Ft float
62.Fn expf "float x"
63.Ft double
64.Fn exp2 "double x"
65.Ft float
66.Fn exp2f "float x"
67.Ft double
68.Fn expm1 "double x"
69.Ft float
70.Fn expm1f "float x"
71.Ft double
72.Fn log "double x"
73.Ft float
74.Fn logf "float x"
75.Ft double
76.Fn log10 "double x"
77.Ft float
78.Fn log10f "float x"
79.Ft double
80.Fn log1p "double x"
81.Ft float
82.Fn log1pf "float x"
83.Ft double
84.Fn pow "double x" "double y"
85.Ft float
86.Fn powf "float x" "float y"
87.Sh DESCRIPTION
88The
89.Fn exp
90and the
91.Fn expf
92functions compute the base
93.Ms e
94exponential value of the given argument
95.Fa x .
96.Pp
97The
98.Fn exp2
99and the
100.Fn exp2f
101functions compute the base 2 exponential of the given argument
102.Fa x .
103.Pp
104The
105.Fn expm1
106and the
107.Fn expm1f
108functions compute the value exp(x)\-1 accurately even for tiny argument
109.Fa x .
110.Pp
111The
112.Fn log
113and the
114.Fn logf
115functions compute the value of the natural logarithm of argument
116.Fa x .
117.Pp
118The
119.Fn log10
120and the
121.Fn log10f
122functions compute the value of the logarithm of argument
123.Fa x
124to base 10.
125.Pp
126The
127.Fn log1p
128and the
129.Fn log1pf
130functions compute
131the value of log(1+x) accurately even for tiny argument
132.Fa x .
133.Pp
134The
135.Fn pow
136and the
137.Fn powf
138functions compute the value
139of
140.Ar x
141to the exponent
142.Ar y .
143.Sh ERROR (due to Roundoff etc.)
144The values of
145.Fn exp 0 ,
146.Fn expm1 0 ,
147.Fn exp2 integer ,
148and
149.Fn pow integer integer
150are exact provided that they are representable.
151.\" XXX Is this really true for pow()?
152Otherwise the error in these functions is generally below one
153.Em ulp .
154.Sh RETURN VALUES
155These functions will return the appropriate computation unless an error
156occurs or an argument is out of range.
157The functions
158.Fn pow x y
159and
160.Fn powf x y
161raise an invalid exception and return an \*(Na if
162.Fa x
163< 0 and
164.Fa y
165is not an integer.
166An attempt to take the logarithm of \*(Pm0 will result in
167a divide-by-zero exception, and an infinity will be returned.
168An attempt to take the logarithm of a negative number will
169result in an invalid exception, and an \*(Na will be generated.
170.Sh NOTES
171The functions exp(x)\-1 and log(1+x) are called
172expm1 and logp1 in
173.Tn BASIC
174on the Hewlett\-Packard
175.Tn HP Ns \-71B
176and
177.Tn APPLE
178Macintosh,
179.Tn EXP1
180and
181.Tn LN1
182in Pascal, exp1 and log1 in C
183on
184.Tn APPLE
185Macintoshes, where they have been provided to make
186sure financial calculations of ((1+x)**n\-1)/x, namely
187expm1(n\(**log1p(x))/x, will be accurate when x is tiny.
188They also provide accurate inverse hyperbolic functions.
189.Pp
190The function
191.Fn pow x 0
192returns x**0 = 1 for all x including x = 0, \*(If, and \*(Na .
193Previous implementations of pow may
194have defined x**0 to be undefined in some or all of these
195cases.
196Here are reasons for returning x**0 = 1 always:
197.Bl -enum -width indent
198.It
199Any program that already tests whether x is zero (or
200infinite or \*(Na) before computing x**0 cannot care
201whether 0**0 = 1 or not.
202Any program that depends
203upon 0**0 to be invalid is dubious anyway since that
204expression's meaning and, if invalid, its consequences
205vary from one computer system to another.
206.It
207Some Algebra texts (e.g.\& Sigler's) define x**0 = 1 for
208all x, including x = 0.
209This is compatible with the convention that accepts a[0]
210as the value of polynomial
211.Bd -literal -offset indent
212p(x) = a[0]\(**x**0 + a[1]\(**x**1 + a[2]\(**x**2 +...+ a[n]\(**x**n
213.Ed
214.Pp
215at x = 0 rather than reject a[0]\(**0**0 as invalid.
216.It
217Analysts will accept 0**0 = 1 despite that x**y can
218approach anything or nothing as x and y approach 0
219independently.
220The reason for setting 0**0 = 1 anyway is this:
221.Bd -ragged -offset indent
222If x(z) and y(z) are
223.Em any
224functions analytic (expandable
225in power series) in z around z = 0, and if there
226x(0) = y(0) = 0, then x(z)**y(z) \(-> 1 as z \(-> 0.
227.Ed
228.It
229If 0**0 = 1, then
230\*(If**0 = 1/0**0 = 1 too; and
231then \*(Na**0 = 1 too because x**0 = 1 for all finite
232and infinite x, i.e., independently of x.
233.El
234.Sh SEE ALSO
235.Xr fenv 3 ,
236.Xr math 3
237