CKTIS / C
exp — C23 mathematical function
`exp(x)` from `<math.h>` computes the base-e exponential and returns `e^x` as `double`; `expf` and `expl` serve `float` and `long double`. C23 requires a range error when the magnitude of finite `x` is too large.
Version: C23
Syntax
double exp(double x);exp(x) from <math.h> computes the base-e exponential and returns e^x as double; expf and expl serve float and long double. C23 requires a range error when the magnitude of finite x is too large.
The example calls exp for -1.0, 0.0, and 1.0. Output 0.368 1.000 2.718 shows the reciprocal values e^-1 and e, plus the exact anchor exp(0).
A large positive argument can overflow and a large negative one can underflow; handle them through math_errhandling. When computing e^x - 1 for small x, use expm1 to avoid digit loss. Annex F guarantees exp(±0)=1, exp(-∞)=+0, and exp(+∞)=+∞.
Examples
#include <math.h>
#include <stdio.h>
int main(void) {
printf("%.3f %.3f %.3f\n", exp(-1.0), exp(0.0), exp(1.0));
return 0;
}
Result
0.368 1.000 2.718
The example calls `exp` for `-1.0`, `0.0`, and `1.0`. Output `0.368 1.000 2.718` shows the reciprocal values `e^-1` and `e`, plus the exact anchor `exp(0)`.