Calculates the natural exponential of a number #include <math.h> double exp ( double x ); float expf ( float x ); long double expl ( long double x ); 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.
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. See AlsoThe C99 exponential functions exp2( ) and expm1( ); the exponential functions for complex numbers: cexp( ), cexpf( ), and cexpl( ); the general exponential function, pow( ) |