Name
expm1
Synopsis
Calculates the natural exponential of a number, minus one
#include <math.h> doubleexpm1
( doublex
); floatexpm1f
( floatx
); long doubleexpm1l
( long doublex
);
The return value of the expm1()
function is one less than
e raised to the power of the
function’s argument, or ex, where
e is Euler’s number,
2.718281.... The expm1()
function
is designed to yield a more accurate result than the expression
exp(
x
)-1
, especially when the value of the
argument is close to zero. If the result is beyond the range of the
function’s type, a range error occurs.
Example
/* let y = (−e^(−2x) − 1 ) / (e^(−2x) + 1), for certain values of x */
double w, x, y;
if (( x > 1.0E-12 ) && ( x < 1.0 ))
{ w =expm1
( -(x+x) );
y = − w / ( w + 2.0 );
}
else
/* ... handle other values of x ... */
Get C in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.