xref: /dragonfly/contrib/openbsd_libm/man/exp.3 (revision 0db87cb7)
1.\"	$OpenBSD: exp.3,v 1.29 2015/01/15 19:06:31 schwarze Exp $
2.\"
3.\" Copyright (c) 1985, 1991 Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. Neither the name of the University nor the names of its contributors
15.\"    may be used to endorse or promote products derived from this software
16.\"    without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.\"     from: @(#)exp.3	6.12 (Berkeley) 7/31/91
31.\"
32.Dd $Mdocdate: January 15 2015 $
33.Dt EXP 3
34.Os
35.Sh NAME
36.Nm exp ,
37.Nm expf ,
38.Nm expl ,
39.Nm exp2 ,
40.Nm exp2f ,
41.Nm exp2l ,
42.Nm expm1 ,
43.Nm expm1f ,
44.Nm expm1l ,
45.Nm log ,
46.Nm logf ,
47.Nm logl ,
48.Nm log2 ,
49.Nm log2f ,
50.Nm log2l ,
51.Nm log10 ,
52.Nm log10f ,
53.Nm log10l ,
54.Nm log1p ,
55.Nm log1pf ,
56.Nm log1pl ,
57.Nm pow ,
58.Nm powf ,
59.Nm powl
60.Nd exponential, logarithm, power functions
61.Sh SYNOPSIS
62.In math.h
63.Ft double
64.Fn exp "double x"
65.Ft float
66.Fn expf "float x"
67.Ft long double
68.Fn expl "long double x"
69.Ft double
70.Fn exp2 "double x"
71.Ft float
72.Fn exp2f "float x"
73.Ft long double
74.Fn exp2l "long double x"
75.Ft double
76.Fn expm1 "double x"
77.Ft float
78.Fn expm1f "float x"
79.Ft long double
80.Fn expm1l "long double x"
81.Ft double
82.Fn log "double x"
83.Ft float
84.Fn logf "float x"
85.Ft long double
86.Fn logl "long double x"
87.Ft double
88.Fn log2 "double x"
89.Ft float
90.Fn log2f "float x"
91.Ft long double
92.Fn log2l "long double x"
93.Ft double
94.Fn log10 "double x"
95.Ft float
96.Fn log10f "float x"
97.Ft long double
98.Fn log10l "long double x"
99.Ft double
100.Fn log1p "double x"
101.Ft float
102.Fn log1pf "float x"
103.Ft long double
104.Fn log1pl "long double x"
105.Ft double
106.Fn pow "double x" "double y"
107.Ft float
108.Fn powf "float x" "float y"
109.Ft long double
110.Fn powl "long double x" "long double y"
111.Sh DESCRIPTION
112The
113.Fn exp
114function computes the base
115.Ms e
116exponential value of the given argument
117.Fa x .
118The
119.Fn expf
120function is a single precision version of
121.Fn exp .
122The
123.Fn expl
124function is an extended precision version of
125.Fn exp .
126.Pp
127The
128.Fn exp2
129function computes the base 2 exponential of the given argument
130.Fa x .
131The
132.Fn exp2f
133function is a single precision version of
134.Fn exp2 .
135The
136.Fn exp2l
137function is an extended precision version of
138.Fn exp2 .
139.Pp
140The
141.Fn expm1
142function computes the value exp(x)\-1 accurately even for tiny argument
143.Fa x .
144The
145.Fn expm1f
146function is a single precision version of
147.Fn expm1 .
148The
149.Fn expm1l
150function is an extended precision version of
151.Fn expm1 .
152.Pp
153The
154.Fn log
155function computes the value of the natural logarithm of argument
156.Fa x .
157The
158.Fn logf
159function is a single precision version of
160.Fn log .
161The
162.Fn logl
163function is an extended precision version of
164.Fn log .
165.Pp
166The
167.Fn log2
168function computes the value of the logarithm of argument
169.Fa x
170to base 2.
171The
172.Fn log2f
173function is a single precision version of
174.Fn log2 .
175The
176.Fn log2l
177function is an extended precision version of
178.Fn log2 .
179.Pp
180The
181.Fn log10
182function computes the value of the logarithm of argument
183.Fa x
184to base 10.
185The
186.Fn log10f
187function is a single precision version of
188.Fn log10 .
189The
190.Fn log10l
191function is an extended precision version of
192.Fn log10 .
193.Pp
194The
195.Fn log1p
196function computes
197the value of log(1+x) accurately even for tiny argument
198.Fa x .
199The
200.Fn log1pf
201function is a single precision version of
202.Fn log1p .
203The
204.Fn log1pl
205function is an extended precision version of
206.Fn log1p .
207.Pp
208The
209.Fn pow
210function computes the value of
211.Ar x
212to the exponent
213.Ar y .
214The
215.Fn powf
216function is a single precision version of
217.Fn pow .
218The
219.Fn powl
220function is an extended precision version of
221.Fn pow .
222.Sh RETURN VALUES
223These functions will return the appropriate computation unless an error
224occurs or an argument is out of range.
225The functions
226.Fn exp ,
227.Fn expm1
228and
229.Fn pow
230detect if the computed value will overflow,
231set the global variable
232.Va errno
233to
234.Er ERANGE
235and cause a reserved operand fault on a VAX or Tahoe.
236The function
237.Fn pow x y
238checks to see if
239.Fa x
240< 0 and
241.Fa y
242is not an integer, in the event this is true,
243the global variable
244.Va errno
245is set to
246.Er EDOM
247and on the VAX and Tahoe generate a reserved operand fault.
248On a VAX and Tahoe,
249.Va errno
250is set to
251.Er EDOM
252and the reserved operand is returned
253by log unless
254.Fa x
255> 0, by
256.Fn log1p
257unless
258.Fa x
259> \-1.
260.Sh ERRORS (due to Roundoff etc.)
261exp(x), log(x), expm1(x) and log1p(x) are accurate to within
262an
263.Em ulp ,
264and log10(x) to within about 2
265.Em ulps ;
266an
267.Em ulp
268is one
269.Em Unit
270in the
271.Em Last
272.Em Place .
273The error in
274.Fn pow x y
275is below about 2
276.Em ulps
277when its
278magnitude is moderate, but increases as
279.Fn pow x y
280approaches
281the over/underflow thresholds until almost as many bits could be
282lost as are occupied by the floating\-point format's exponent
283field; that is 8 bits for
284.Dq VAX D
285and 11 bits for IEEE 754 Double.
286No such drastic loss has been exposed by testing; the worst
287errors observed have been below 20
288.Em ulps
289for
290.Dq VAX D ,
291300
292.Em ulps
293for IEEE 754 Double.
294Moderate values of
295.Fn pow
296are accurate enough that
297.Fn pow integer integer
298is exact until it is bigger than 2**56 on a VAX,
2992**53 for IEEE 754.
300.Sh NOTES
301The functions exp(x)\-1 and log(1+x) are called
302expm1 and logp1 in BASIC on the Hewlett\-Packard HP-71B
303and APPLE Macintosh, EXP1 and LN1 in Pascal, exp1 and log1 in C
304on APPLE Macintoshes, where they have been provided to make
305sure financial calculations of ((1+x)**n\-1)/x, namely
306expm1(n\(**log1p(x))/x, will be accurate when x is tiny.
307They also provide accurate inverse hyperbolic functions.
308.Pp
309The function
310.Fn pow x 0
311returns x**0 = 1 for all x including x = 0,
312.if n \
313\*(If
314.if t \
315\(if
316(not found on a VAX),
317and
318.Em \*(Na
319(the reserved operand on a VAX).
320Previous implementations of
321.Fn pow
322may have defined x**0 to be undefined in some or all of these cases.
323Here are reasons for returning x**0 = 1 always:
324.Bl -enum -width indent
325.It
326Any program that already tests whether x is zero (or
327infinite or \*(Na) before computing x**0 cannot care
328whether 0**0 = 1 or not.
329Any program that depends upon 0**0 to be invalid is dubious anyway since that
330expression's meaning and, if invalid, its consequences
331vary from one computer system to another.
332.It
333Some Algebra texts (e.g., Sigler's) define x**0 = 1 for
334all x, including x = 0.
335This is compatible with the convention that accepts a[0]
336as the value of polynomial
337.Bd -literal -offset indent
338p(x) = a[0]\(**x**0 + a[1]\(**x**1 + a[2]\(**x**2 +...+ a[n]\(**x**n
339.Ed
340.Pp
341at x = 0 rather than reject a[0]\(**0**0 as invalid.
342.It
343Analysts will accept 0**0 = 1 despite that x**y can
344approach anything or nothing as x and y approach 0
345independently.
346The reason for setting 0**0 = 1 anyway is this:
347.Bd -filled -offset indent
348If x(z) and y(z) are
349.Em any
350functions analytic (expandable
351in power series) in z around z = 0, and if there
352x(0) = y(0) = 0, then x(z)**y(z) \(-> 1 as z \(-> 0.
353.Ed
354.It
355If 0**0 = 1, then
356.if n \
357\*(If**0 = 1/0**0 = 1 too; and
358.if t \
359\(if**0 = 1/0**0 = 1 too; and
360then \*(Na**0 = 1 too because x**0 = 1 for all finite
361and infinite x, i.e., independently of x.
362.El
363.Sh SEE ALSO
364.Xr ilogb 3 ,
365.Xr infnan 3
366.Sh HISTORY
367The
368.Fn exp
369and
370.Fn log
371functions first appeared in
372.At v1 ;
373.Fn pow
374in
375.At v3 ;
376.Fn log10
377in
378.At v7 ;
379.Fn log1p
380and
381.Fn expm1
382in
383.Bx 4.3 .
384