home *** CD-ROM | disk | FTP | other *** search
- /*********
- *
- * DEPDB.C
- *
- * by Ralph Davis
- * modified by Tom Rettig
- *
- * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
- *
- *********/
-
- /* DEPDB : Depreciation by declining-balance method
-
- Computes depreciation calculated as percent
- of current value.
-
- SYNTAX: DEPDB(value, rate, periods)
-
- where value = current value
- rate = depreciation rate per period
- periods = number of periods in calculations
-
- RETURNS: depreciation over specified period of time.
- */
-
- #include "trlib.h"
-
- TRTYPE depdb()
- {
- if ( PCOUNT==3 && ISNUM(1) && ISNUM(2) && ISNUM(3) )
- {
- double value = _parnd(1);
- double rate = _parnd(2);
- int periods = (int)_parnd(3);
-
- double depr = 0;
- int i;
-
- for (i = 0; i < periods; i++)
- {
- depr += value * rate; /* Depreciation = value times
- rate of depreciation */
- value *= (1.0 - rate); /* New value = old value reduced
- by rate of depreciation */
- }
- _retnd(depr);
- }
- else
- _retnd( (double)ERROR );
- }
-