exp(3) — Subroutines
Digital
NAME
exp, fexp, expm1, fexp1, log, flog, log10, flog10, log1p, flog1p, pow − Computes exponential, logarithm, and power functions.
LIBRARY
Math Library (libm.a)
SYNOPSIS
#include <math.h>
double exp (
double x); float fexp (
float x); double expm1 (
double x); float fexpm1 (
float x); double log (
double x); float flog (
float x); double log10 (
double x); float flog10 (
float x);
double log1p (
double x); float flog1p (
float x);
double pow (
double x,
double y);
PARAMETERS
xSpecifies some double or float value.
ySpecifies some double or float value.
DESCRIPTION
The exp() and fexp() functions compute the exponential function of x, defined as ex, where e is the constant used as a base for natural logarithms, for double and float data types respectively.
The expm1() and fexpm1() functions compute exp(x)-1 accurately, even for tiny x, for double and float data types respectively.
The log() and flog() functions compute the natural logarithm of x for double and float data types respectively.
The log10() and flog10() functions compute the base 10 logarithm of x for double and float data types respectively.
The log1p() and flog1p() functions compute log(1+x) accurately, even for tiny x, for double and float data types respectively.
The pow() function computes the value of x raised to the power of y (xy). If x is negative, y must be an integral value. If x is 0 (zero), y must be nonnegative. The pow(x,0.0) function call returns 1.0 for all x.
NOTES
pow(x,0) returns x∗∗0=1 for all x including x=0, Infinity, and NaN. Other implementations of pow might define x∗∗0 to be undefined. Reasons for always returning x∗∗0=1 are as follows:
1.Any program that already tests whether x is zero (or infinite or NaN) before computing x∗∗0 cannot consider it important whether or not 0∗∗0=1. Any program that depends on 0∗∗0 to be invalid is using dubious logic because the expression’s meaning and, if invalid, its consequences vary from one computer system to another.
2.Some algebra texts (for example, the one by Sigler) define x∗∗0=1 for all x, including x=0. This definition is compatible with the convention that accepts a[0] as the value of the polynomial p(x)=a[0]∗x∗∗0+a[1]∗x∗∗1+a[2]∗x∗∗2+...+a[n]∗x∗∗n at x=0 rather than rejecting a[0]∗0∗∗0 as invalid.
3.Analysts will accept 0∗∗0=1 despite the fact that x∗∗y can approach anything or nothing as x and y approach 0 independently. Remember that the reason for setting 0∗∗0=1 is the following one: If x(z) and y(z) are any functions analytic (expandable in power series) in z around z=0, and if x(0)=y(0)=0, then x(z)∗∗y(z)->1 as z->0.
4.If 0∗∗0=1, then infinity∗∗0=1/0∗∗0 and NaN∗∗0=1 because x∗∗0=1 for all finite and infinite x; in other words, the value of x∗∗0=1 is not dependent on the value of x.
The exp(), log10(), log(), and pow() functions are supported for multi-threaded applications.
AES Support Level:
Full use for exp(), log10(), log(), and pow() only.
RETURN VALUES
Upon successful completion, exp() returns the value of the exponential function of x. If the correct value would overflow, the exp() function returns HUGE_VAL and sets errno to [ERANGE]. If the correct value would underflow, the exp() function returns zero. If x is NaN, NaN is returned.
The log() function returns the natural logarithm of x. The value of x must be positive. If x is NaN, NaN is returned. Otherwise, either −HUGE_VAL or NaN is returned and errno is set to indicate the error.
The log10() function returns the base 10 logarithm of x. The value of x must be positive. If x is NaN, NaN is returned and errno may be set to [EDOM]. Otherwise, either −HUGE_VAL or NaN is returned and errno is set to indicate the error.
The pow() function returns the value of x raised to the power of y (xy). If x is negative and y is not an integer, NaN is returned. If x is 0 (zero) and y is negative, −HUGE_VAL is returned. If x or y is NaN, NaN is returned and errno is set to [EDOM]. Otherwise, errno is set to indicate the error or [EDOM] is returned.
ERRORS
The exp(x), log(x), and log1p(x) routines are accurate to within one ulp (unit in the last place). The log10(x) routine is accurate to within two ulp. The error in the pow(x,y) routine is below about two ulp when its magnitude is moderate but increases as pow(x,y) approaches the overflow/underflow thresholds until almost as many bits could be lost as are occupied by the floating-point format’s exponent field (11 bits for IEEE 754 Double). Note that testing has not exposed a loss as drastic as this; the most loss exposed by testing has been below 300 ulp for IEEE 754 Double. Moderate values of pow are accurate enough that pow(integer,integer) is exact until its value is larger than 2∗∗53 for IEEE 754 Double.
If the exp() function fails, errno may be set to one of the following values:
[ERANGE]The result would overflow.
[EDOM]The value of x is NaN.
[ERANGE]The result would underflow.
If the log() function fails, errno may be set to one of the following values:
[EDOM]The value of x is negative or zero.
[EDOM]The value of x is NaN.
[ERANGE]The logarithm of x cannot be represented, or the result would cause overflow.
If the log10() function fails, errno may be set to one of the following values:
[EDOM]The value of x is negative or zero.
[EDOM]The value of x is NaN.
[ERANGE]The logarithm of x cannot be represented or the result would cause overflow.
If the pow() function fails, errno may be set to one of the following values:
[EDOM]The value of x is negative and y is nonintegral.
[ERANGE]The value to be returned would have caused overflow.
[EDOM]The value of x or y is NaN, or x is zero and y is negative.
[ERANGE]The value to be returned would have caused underflow.
ENVIRONMENT
In the System V habitat, the log1p(), expm1(), fexp(), fexpm1(), flog(), and flog10() functions are not available. Furthermore, the following behavior is exhibited by the exp(), log(), log10(), and pow() functions:
The exp() function returns HUGE when the correct value would overflow, or 0 when the correct value would underflow, and sets errno to ERANGE.
The log() and log10() functions return −HUGE and set errno to EDOM when x is not a positive value. A message that indicates DOMAIN error (or SING error when x is 0) is printed on the standard error output.
The pow() function returns 0 and sets errno to EDOM when x is 0 and y is not positive, or when x is negative and y is not an integer. In these cases, a message that indicates DOMAIN error is printed on the standard error output.
In the System V habitat, you can change the preceding error-handling procedures using the matherr() function.