exp


exp

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.

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. 

See Also

The C99 exponential functions exp2( ) and expm1( ); the exponential functions for complex numbers: cexp( ), cexpf( ), and cexpl( ); the general exponential function, pow( )



C(c) In a Nutshell
C in a Nutshell (In a Nutshell (OReilly))
ISBN: 0596006977
EAN: 2147483647
Year: 2006
Pages: 473

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net