ba237a9d91
Files correlati : Ricompilazione Demo : [ ] Commento : Aggiunti i sorgenti per Greenleaf Math Library (gfm.dll) git-svn-id: svn://10.65.10.50/trunk@10079 c028cbd2-c16b-5b4b-a496-9718f37d4682
122 lines
2.9 KiB
C
Executable File
122 lines
2.9 KiB
C
Executable File
/* DEC *DepreciateDeclining(depr, remval, book, salv,dbf,life,partial,time);
|
|
*
|
|
* ARGUMENT
|
|
* DEC *depr, *remval, *book, *salv, *dbf, *partial;
|
|
* int life, time;
|
|
*
|
|
* DESCRIPTION
|
|
* Calculate a specific year's depreciation and remaining depreciable
|
|
* value according to declining balance depreciation.
|
|
* With a declining balance factor of dbf, the item has book value
|
|
* book, salvage value salv, and lifetime life (which may include a partial
|
|
* period). At year# time, the depreciation and remaining value are
|
|
* computed and stored in depr and remval. The first year is always
|
|
* the partial year.
|
|
*
|
|
* SIDE EFFECTS
|
|
* depr and remval are changed.
|
|
*
|
|
* RETURNS
|
|
* depr if successful, otherwise GM_NULL.
|
|
*
|
|
* POSSIBLE ERRORS
|
|
* GM_NULLPOINTER
|
|
* GM_ARGVAL
|
|
*
|
|
* AUTHOR
|
|
* Jared Levy
|
|
* Copyright (C) 1988-1990 Greenleaf Software Inc. All rights reserved.
|
|
*
|
|
* MODIFICATIONS
|
|
*
|
|
*
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include "gm.h"
|
|
#include "gmsystem.h"
|
|
|
|
DEC *DepreciateDeclining(depr, remval, book, salv,dbf,life, partial, time)
|
|
DEC *depr, *remval, *book, *salv, *dbf, *partial;
|
|
int life, time;
|
|
{
|
|
int i, plife;
|
|
DEC drbv, *rbv=&drbv, dfol, *fol=&dfol;
|
|
DEC dtemp, *temp=&dtemp, dnsalv, *nsalv=&dnsalv;
|
|
|
|
_MacStart(GM_DPDB);
|
|
|
|
if (!depr||!remval||!book||!salv||!partial||!dbf) {
|
|
_MacErr(GM_NULLPOINTER);
|
|
_MacRet(GM_NULL);
|
|
}
|
|
if (_MacBad(salv)||_MacBad(partial)||_MacBad(dbf)) {
|
|
_MacErr(GM_INIT);
|
|
_MacRet(GM_NULL);
|
|
}
|
|
|
|
plife=life+(_MacIsDecZ(partial)?0:1);
|
|
|
|
if (time<0||life<1||_MacIsDecN(book)||_MacIsDecN(salv)||time>plife
|
|
||_MacIsDecN(dbf)
|
|
||_MacIsDecN(partial)||CompareDecimal(partial,&decOne)==1) {
|
|
_MacDZero(depr);
|
|
_MacDZero(remval);
|
|
_MacErr(GM_ARGVAL);
|
|
_MacRet(GM_NULL);
|
|
}
|
|
|
|
(void) _ScaleDec80Bit(rbv, book, 2);
|
|
(void) _ScaleDec80Bit(nsalv, salv, 2);
|
|
(void) _SubDec80Bit(remval, rbv, nsalv);
|
|
|
|
if (time==0) {
|
|
_MacDZero(depr);
|
|
_MacRet(depr);
|
|
}
|
|
|
|
(void) ConvLongToDecimal(temp, (long) life * 100L);
|
|
(void) _DivDec80Bit(fol, dbf, temp);
|
|
|
|
/* handle partial first year */
|
|
if (_MacIsDecZ(partial)) {
|
|
i=0;
|
|
}
|
|
else {
|
|
(void) _MulDec80Bit(temp,rbv,fol);
|
|
(void) _MulDec80Bit(depr, temp, partial);
|
|
(void) _ScaleDec80Bit(depr,depr,2);
|
|
(void) _SubDec80Bit(remval, remval, depr);
|
|
/* remaining value can't be negative */
|
|
if (_MacIsDecN(remval)) {
|
|
(void) _AddDec80Bit(depr, depr, remval);
|
|
_MacDZero(remval);
|
|
}
|
|
(void) _SubDec80Bit(rbv, rbv, depr);
|
|
i=1;
|
|
}
|
|
|
|
/* handle remaining years */
|
|
|
|
while (i<time) {
|
|
i++;
|
|
(void) _MulDec80Bit(depr, rbv, fol);
|
|
(void) _ScaleDec80Bit(depr,depr,2);
|
|
(void) _SubDec80Bit(remval, remval, depr);
|
|
/* remaining value can't be negative */
|
|
if (_MacIsDecN(remval)) {
|
|
(void) _AddDec80Bit(depr, depr, remval);
|
|
_MacDZero(remval);
|
|
}
|
|
(void) _SubDec80Bit(rbv,rbv,depr);
|
|
}
|
|
|
|
/* remaining depreciable value after last year should be 0 */
|
|
if (time==plife&&!_MacIsDecZ(remval)) {
|
|
(void) _AddDec80Bit(depr,depr,remval);
|
|
_MacDZero(remval);
|
|
}
|
|
|
|
_MacRet(depr);
|
|
}
|