expm1

 

Description

Compute exp(x)-1 accurately for small values of x.

Syntax

double expm1( double x )

Parameters

x
[input] independent variable

Return

exp(x) - 1

Examples

EX1

void expm1_ex1()
{
    double x = 0.0000000000000001;
    double answer = expm1(x);

    printf("expm1(%.30f) = %.30f\n", x, answer); // Result is "expm1(0.000000000000000100000000000000) = 0.000000000000000100000000000000"
}

EX2

void expm1_ex2()
{
    double x = 0.000000000000001;
    double answer = expm1(x);

    printf("expm1(%.30f) = %.30f\n", x, answer); // Result is "expm1(0.000000000000001000000000000000) = 0.000000000000001110223024625157"
}

Remark

This funciton is used to calculate when x is very close to zero. For this case, expm1(x) is approximately x, whereas exp(x) - 1 can be zero.

See Also

exp

Header to Include

origin.h

Reference