home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / xbase / library / clipper / rettig / source / inctime.c < prev    next >
C/C++ Source or Header  |  1990-10-21  |  1KB  |  49 lines

  1. /*********
  2. *
  3. * INCTIME.C
  4. *
  5. * by Ralph Davis
  6. *
  7. * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
  8. *
  9. *********/
  10.  
  11. /*  INCTIME:  Time to increase
  12.  
  13.               Computes the time required to increase an investment
  14.               by a certain amount
  15.  
  16.               SYNTAX:  INCTIME(increase, rate, conversions)
  17.  
  18.                        where increase    = percentage of increase
  19.                              rate        = annual interest rate
  20.                              conversions = number of times/year
  21.                                            interest is compounded
  22.  
  23.                RETURNS:  number of years required 
  24. */
  25.  
  26. #include "trlib.h"
  27.  
  28. TRTYPE inctime()
  29. {
  30.    double  increase; 
  31.    double  rate;     
  32.    double  conversions;
  33.  
  34.    if (PCOUNT == 3 && ISNUM(1) && ISNUM(2) && ISNUM(3))
  35.    {
  36.       increase    = _parnd(1);
  37.       rate        = _parnd(2);
  38.       conversions = _parnd(3);
  39.  
  40.       if (rate == 0.0 && increase != 0.0)
  41.          _retnd(_tr_infinity());
  42.       else
  43.          _retnd(_tr_log(1.0 + increase) /
  44.             (conversions * (_tr_log(1 + rate / conversions))));
  45.    }
  46.    else
  47.       _retnd( (double)ERROR );
  48. }
  49.