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. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.\"     from: @(#)exp.3	6.12 (Berkeley) 7/31/91
29.\" $FreeBSD: src/lib/msun/man/exp.3,v 1.24 2008/01/18 21:43:00 das Exp $
30.\"	$NetBSD: exp.3,v 1.28 2011/09/17 10:52:52 jruoho Exp $
31.\"
32.Dd $Mdocdate: February 9 2014 $
33.Dt EXP 3
34.Os
35.Sh NAME
36.Nm exp ,
37.Nm expf ,
38.\" The sorting error is intentional.  exp and expf should be adjacent.
39.Nm exp2 ,
40.Nm exp2f ,
41.Nm expm1 ,
42.Nm expm1f ,
43.Nd exponential functions
44.Sh LIBRARY
45.Lb libm
46.Sh SYNOPSIS
47.In math.h
48.Ft double
49.Fn exp "double x"
50.Ft float
51.Fn expf "float x"
52.Ft double
53.Fn exp2 "double x"
54.Ft float
55.Fn exp2f "float x"
56.Ft double
57.Fn expm1 "double x"
58.Ft float
59.Fn expm1f "float x"
60.Sh DESCRIPTION
61The
62.Fn exp
63and the
64.Fn expf
65functions compute the base
66.Ms e
67exponential value of the given argument
68.Fa x .
69.Pp
70The
71.Fn exp2
72and
73.Fn exp2f
74functions compute the base 2 exponential of the given argument
75.Fa x .
76.Pp
77The
78.Fn expm1
79and the
80.Fn expm1f
81functions computes the value exp(x)\-1 accurately even for tiny argument
82.Fa x .
83.Sh RETURN VALUES
84These functions will return the appropriate computation unless an error
85occurs or an argument is out of range.
86The functions
87.Fn exp
88and
89.Fn expm1
90detect if the computed value will overflow,
91set the global variable
92.Va errno
93to
94.Er ERANGE
95and cause a reserved operand fault on a
96.Tn VAX .
97The function
98.Fn pow x y
99checks to see if
100.Fa x
101\*(Lt 0 and
102.Fa y
103is not an integer, in the event this is true,
104the global variable
105.Va errno
106is set to
107.Er EDOM
108and on the
109.Tn VAX
110generate a reserved operand fault.
111On a
112.Tn VAX ,
113.Va errno
114is set to
115.Er EDOM
116and the reserved operand is returned
117by log unless
118.Fa x
119\*(Gt 0, by
120.Fn log1p
121unless
122.Fa x
123\*(Gt \-1.
124.Sh ERRORS
125exp(x), log(x), expm1(x) and log1p(x) are accurate to within
126an
127.Em ulp ,
128and log10(x) to within about 2
129.Em ulps ;
130an
131.Em ulp
132is one
133.Em Unit
134in the
135.Em Last
136.Em Place .
137The error in
138.Fn pow x y
139is below about 2
140.Em ulps
141when its
142magnitude is moderate, but increases as
143.Fn pow x y
144approaches
145the over/underflow thresholds until almost as many bits could be
146lost as are occupied by the floating\-point format's exponent
147field; that is 8 bits for
148.Tn "VAX D"
149and 11 bits for IEEE 754 Double.
150No such drastic loss has been exposed by testing; the worst
151errors observed have been below 20
152.Em ulps
153for
154.Tn "VAX D" ,
155300
156.Em ulps
157for
158.Tn IEEE
159754 Double.
160Moderate values of
161.Fn pow
162are accurate enough that
163.Fn pow integer integer
164is exact until it is bigger than 2**56 on a
165.Tn VAX ,
1662**53 for
167.Tn IEEE
168754.
169.Sh NOTES
170The functions exp(x)\-1 and log(1+x) are called
171expm1 and logp1 in
172.Tn BASIC
173on the Hewlett\-Packard
174.Tn HP Ns \-71B
175and
176.Tn APPLE
177Macintosh,
178.Tn EXP1
179and
180.Tn LN1
181in Pascal, exp1 and log1 in C
182on
183.Tn APPLE
184Macintoshes, where they have been provided to make
185sure financial calculations of ((1+x)**n\-1)/x, namely
186expm1(n\(**log1p(x))/x, will be accurate when x is tiny.
187They also provide accurate inverse hyperbolic functions.
188.Pp
189The function
190.Fn pow x 0
191returns x**0 = 1 for all x including x = 0,
192.if n \
193Infinity
194.if t \
195\(if
196(not found on a
197.Tn VAX ) ,
198and
199.Em NaN
200(the reserved
201operand on a
202.Tn VAX ) .
203Previous implementations of pow may
204have defined x**0 to be undefined in some or all of these
205cases.
206Here are reasons for returning x**0 = 1 always:
207.Bl -enum -width indent
208.It
209Any program that already tests whether x is zero (or
210infinite or \*(Na) before computing x**0 cannot care
211whether 0**0 = 1 or not.
212Any program that depends
213upon 0**0 to be invalid is dubious anyway since that
214expression's meaning and, if invalid, its consequences
215vary from one computer system to another.
216.It
217Some Algebra texts (e.g. Sigler's) define x**0 = 1 for
218all x, including x = 0.
219This is compatible with the convention that accepts a[0]
220as the value of polynomial
221.Bd -literal -offset indent
222p(x) = a[0]\(**x**0 + a[1]\(**x**1 + a[2]\(**x**2 +...+ a[n]\(**x**n
223.Ed
224.Pp
225at x = 0 rather than reject a[0]\(**0**0 as invalid.
226.It
227Analysts will accept 0**0 = 1 despite that x**y can
228approach anything or nothing as x and y approach 0
229independently.
230The reason for setting 0**0 = 1 anyway is this:
231.Bd -filled -offset indent
232If x(z) and y(z) are
233.Em any
234functions analytic (expandable
235in power series) in z around z = 0, and if there
236x(0) = y(0) = 0, then x(z)**y(z) \(-\*(Gt 1 as z \(-\*(Gt 0.
237.Ed
238.It
239If 0**0 = 1, then
240.if n \
241infinity**0 = 1/0**0 = 1 too; and
242.if t \
243\(if**0 = 1/0**0 = 1 too; and
244then \*(Na**0 = 1 too because x**0 = 1 for all finite
245and infinite x, i.e., independently of x.
246.El
247.Sh SEE ALSO
248.Xr math 3
249.Sh STANDARDS
250The
251.Fn exp
252functions conform to
253.St -ansiC .
254The
255.Fn exp2 ,
256.Fn exp2f ,
257.Fn expf ,
258.Fn expm1 ,
259and
260.Fn expm1f
261functions conform to
262.St -isoC-99 .
263.Sh HISTORY
264The
265.Fn exp
266functions appeared in
267.At v6 .
268The
269.Fn expm1
270function appeared in
271.Bx 4.3 .
272