Name
exp
Synopsis
Calculates the natural exponential of a number
#include <math.h> doubleexp
( doublex
); floatexpf
( floatx
); long doubleexpl
( long doublex
);
The return value of the exp()
function is e raised to the power of the function’s
argument, or ex, where
e is Euler’s number,
2.718281.... If the result is beyond the range of the function’s
type, a range error occurs.
Tip
The natural exponential function exp()
is the inverse of the natural
logarithm function, log()
.
Example
/* Amount owed = principal * e**(interest_rate * time) */
int principal = 10000; // Initial debt is ten thousand dollars.
int balance = 0;
double rate = 0.055; // Interest rate is 5.5% annually.
double time = 1.5; // Period is eighteen months.
balance = principal *exp
( rate * time );
printf("Invest %d dollars at %.1f%% compound interest, and "
"in %.1f years you'll have %d dollars.\n",
principal, rate*100.0, time, balance );
This code produces the following output:
Invest 10000 dollars at 5.5% compound interest, and in 1.5 years you'll have 10859 dollars.
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.