C expm1() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
math.h

Definition

In C, expm1() returns exp(x) - 1. It stays accurate when x is near 0, where exp(x) is near 1.

You pass one double. The result is a double. Include <math.h>. On GCC, link with -lm.

Syntax

Pass the exponent. Start with this call.

C
expm1(1e-9);
CallWhat it does
expm1(0.0)Returns 0.
expm1(1e-9)Returns a value near 1e-9, without losing digits.

Include <math.h>. On GCC, link with -lm. Prefer expm1(x) over exp(x) - 1 for tiny x.

Library declarations
C
double expm1(double x);
float expm1f(float x);
long double expm1l(long double x);

Parameters

ParameterDescription
xRequired. The exponent used inside exp(x) - 1.

Return Value

Return ValueDescription
doubleexp(x) - 1. For small x, more accurate than writing exp(x) - 1 yourself.

C Examples

Example 1 — Basic expm1 Values

Print expm1 at 0 and 1.

C
#include <stdio.h>
#include <math.h>

int main(void) {
    printf("%.6f\n", expm1(0.0));
    printf("%.6f\n", expm1(1.0));
    return 0;
}

How It Works

  1. Include math.h. That declares expm1.
  2. Zero input. expm1(0) is 0.
  3. Unit input. expm1(1) is e − 1 ≈ 1.718.
  4. Same idea as exp. Just shifted by subtracting 1 carefully.

Example 2 — Tiny x Accuracy

Compare exp(x) - 1 with expm1(x) for a very small x.

C
#include <stdio.h>
#include <math.h>

int main(void) {
    double x = 1e-12;
    printf("exp-1  = %.12e\n", exp(x) - 1.0);
    printf("expm1  = %.12e\n", expm1(x));
    return 0;
}

How It Works

  1. Pick a tiny x. 1e-12 is near zero.
  2. Naive form. exp(x) - 1 can be slightly off.
  3. Stable form. expm1(x) stays closer to x.
  4. Lesson. Use the dedicated function for small deltas.

Example 3 — Percent-Style Growth

Turn a small rate into a growth factor minus one.

C
#include <stdio.h>
#include <math.h>

int main(void) {
    double rate = 0.02;
    double change = expm1(rate);

    printf("relative change ≈ %.6f\n", change);
    return 0;
}

How It Works

  1. Choose a rate. 0.02 means about 2%.
  2. Call expm1. Convert continuous growth into a relative change.
  3. Read the result. Slightly above 0.02, as expected.
  4. Why expm1. Cleaner than exp(rate) - 1 for small rates.

Frequently Asked Questions

expm1() returns exp(x) - 1. It is accurate even when x is very small.
x is required. It is the double exponent.
A double equal to exp(x) - 1. expm1(0) is 0.
Include <math.h>. On GCC, link with -lm.
Use expm1 when you need exp(x) - 1 and x may be near zero. Plain subtraction can lose precision.

Next: fabs()

Return the absolute value of a floating-point number.

fabs() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful