Commit | Line | Data |
---|---|---|
f15d45ab | 1 | .TH EXP 3M "19 August 1985" |
6a716ef9 | 2 | .UC 4 |
f15d45ab | 3 | .ds nn \fINaN\fR |
6071f222 | 4 | .SH NAME |
f15d45ab | 5 | exp, expm1, log, log10, log1p, pow \- exponential, logarithm, power |
6071f222 KM |
6 | .SH SYNOPSIS |
7 | .nf | |
8 | .B #include <math.h> | |
9 | .PP | |
f15d45ab | 10 | .B double exp(x) |
6a716ef9 MAN |
11 | .B double x; |
12 | .PP | |
f15d45ab | 13 | .B double expm1(x) |
6071f222 KM |
14 | .B double x; |
15 | .PP | |
16 | .B double log(x) | |
17 | .B double x; | |
18 | .PP | |
19 | .B double log10(x) | |
20 | .B double x; | |
21 | .PP | |
f15d45ab MAN |
22 | .B double log1p(x) |
23 | .B double x; | |
24 | .PP | |
25 | .B double pow(x,y) | |
26 | .B double x,y; | |
6071f222 KM |
27 | .fi |
28 | .SH DESCRIPTION | |
6a716ef9 | 29 | .PP |
f15d45ab MAN |
30 | Exp returns the exponential function of x. |
31 | .PP | |
32 | Expm1 returns exp(x)\-1 accurately even for tiny x. | |
6a716ef9 | 33 | .PP |
f15d45ab | 34 | Log returns the natural logarithm of x. |
6071f222 | 35 | .PP |
f15d45ab | 36 | Log10 returns the logarithm of x to base 10. |
6071f222 | 37 | .PP |
f15d45ab MAN |
38 | Log1p returns log(1+x) accurately even for tiny x. |
39 | .PP | |
40 | Pow(x,y) returns | |
b8757a44 | 41 | .if n \ |
f15d45ab | 42 | x**y. |
b8757a44 | 43 | .if t \ |
f15d45ab | 44 | x\u\s8y\s10\d. |
6071f222 | 45 | .SH SEE ALSO |
f15d45ab MAN |
46 | intro(3M), infnan(3M) |
47 | .SH ERROR (due to Roundoff etc.) | |
48 | exp(x), log(x), expm1(x) and log1p(x) are accurate to within | |
49 | an \fIulp\fR, and log10(x) to within about 2 \fIulp\fRs; | |
50 | an \fIulp\fR is one \fIU\fRnit in the \fIL\fRast \fIP\fRlace. | |
51 | The error in pow(x,y) is below about 2 \fIulp\fRs when its | |
52 | magnitude is moderate, but increases as pow(x,y) approaches | |
53 | the over/underflow thresholds until almost as many bits are | |
54 | lost as are occupied by the floating\-point format's exponent | |
55 | field; that is 8 bits for VAX D and 11 bits for IEEE 754 Double. | |
56 | Moderate values of pow are accurate enough that pow(integer,integer) | |
57 | is exact until it is bigger than 2**56 on a VAX, 2**53 for IEEE. | |
6071f222 | 58 | .SH DIAGNOSTICS |
f15d45ab MAN |
59 | Exp, expm1 and pow return the reserved operand on a VAX when the correct |
60 | value would overflow, and they set \fIerrno\fR to ERANGE. | |
61 | Pow(x,y) returns the reserved operand on a VAX and sets \fIerrno\fR | |
62 | to EDOM when x < 0 and y is not an integer. | |
6071f222 | 63 | .PP |
f15d45ab MAN |
64 | On a VAX, \fIerrno\fR is set to EDOM and the reserved operand is returned |
65 | by log unless x > 0, by log1p unless x > \-1. | |
7ccdb75f | 66 | .SH NOTES |
f15d45ab MAN |
67 | The functions exp(x)\-1 and log(1+x) are called expm1 |
68 | and logp1 in BASIC on the Hewlett\-Packard HP\-71B and APPLE | |
69 | Macintosh, EXP1 and LN1 in Pascal, exp1 and log1 in C | |
70 | on APPLE Macintoshes, where they have been provided to make | |
71 | sure financial calculations of ((1+x)**n\-1)/x, namely | |
72 | expm1(n\(**log1p(x))/x, will be accurate when x is tiny. | |
73 | They also provide accurate inverse hyperbolic functions. | |
74 | .PP | |
75 | Pow(x,0) returns x**0 = 1 for all x including x = 0, | |
76 | .if n \ | |
77 | Infinity | |
78 | .if t \ | |
7ccdb75f | 79 | \(if |
f15d45ab MAN |
80 | (not found on a VAX), and \*(nn (the reserved |
81 | operand on a VAX). Previous implementations of pow may | |
82 | have defined x**0 to be undefined in some or all of these | |
83 | cases. Here are reasons for returning x**0 = 1 always: | |
84 | .IP (1) \w'\0\0\0\0'u | |
85 | Any program that already tests whether x is zero (or | |
86 | infinite or \*(nn) before computing x**0 cannot care | |
87 | whether 0**0 = 1 or not. Any program that depends | |
88 | upon 0**0 to be invalid is dubious anyway since that | |
89 | expression's meaning and, if invalid, its consequences | |
90 | vary from one computer system to another. | |
91 | .IP (2) \w'\0\0\0\0'u | |
92 | Some Algebra texts (e.g. Sigler's) define x**0 = 1 for | |
93 | all x, including x = 0. | |
94 | This is compatible with the convention that accepts a[0] | |
95 | as the value of polynomial | |
96 | .ce | |
97 | p(x) = a[0]\(**x**0 + a[1]\(**x**1 + a[2]\(**x**2 +...+ a[n]\(**x**n | |
98 | .IP | |
99 | at x = 0 rather than reject a[0]\(**0**0 as invalid. | |
100 | .IP (3) \w'\0\0\0\0'u | |
101 | Analysts will accept 0**0 = 1 despite that x**y can | |
102 | approach anything or nothing as x and y approach 0 | |
7ccdb75f | 103 | independently. |
f15d45ab MAN |
104 | The reason for setting 0**0 = 1 anyway is this: |
105 | .IP | |
106 | If x(z) and y(z) are \fIany\fR functions analytic (expandable | |
107 | in power series) in z around z = 0, and if there | |
108 | x(0) = y(0) = 0, then x(z)**y(z) \(-> 1 as z \(-> 0. | |
109 | .IP (4) \w'\0\0\0\0'u | |
110 | If 0**0 = 1, then | |
111 | .if n \ | |
112 | infinity**0 = 1/0**0 = 1 too; and | |
113 | .if t \ | |
114 | \(if**0 = 1/0**0 = 1 too; and | |
115 | then \*(nn**0 = 1 too because x**0 = 1 for all finite | |
116 | and infinite x, i.e. independently of x. | |
6a716ef9 | 117 | .SH AUTHOR |
7ccdb75f | 118 | Kwok\-Choi Ng, W. Kahan |