campo-sirio/gfm/dpct.c

102 lines
1.6 KiB
C
Raw Normal View History

/* int DecimalPercentage(pDst,src,opt);
*
* ARGUMENT
* DEC *pDst; dest
* DEC *src; source
* int opt; option
*
* DESCRIPTION
* According to the option opt,
* opt = 1 dst = src * 100
* opt = 2 dst = src / 100
* opt = 3 dst = src / 1200
*
* SIDE EFFECTS
* None.
*
* RETURNS
* Returns ptr to pDst if successful, else GM_NULL.
*
* POSSIBLE ERROR CODES:
*
* GM_NULLPOINTER
* GM_OVERFLOW
* GM_UNDERFLOW
* GM_ARGVAL
*
* AUTHOR
* Andy Anderson 20-Feb-87 16:35
* Copyright (C) 1987-1990 Greenleaf Software Inc. All rights reserved.
*
* MODIFICATIONS
*
*/
#include <stdio.h>
#include "gm.h"
#include "gmsystem.h"
DEC *DecimalPercentage(pDst,src,opt)
DEC *pDst, *src;
int opt;
{
DEC dcons, *cons=&dcons;
_MacStart(GM_DPCT);
_MacInVarD(src);
_MacOutVarD(pDst);
if ((opt<1)||(opt>3)) {
_MacErr(GM_ARGVAL);
_MacRet(GM_NULL);
}
_MacOutVar(pDst,GM_NULL);
if (_MacIsDecZ(src)) {
_MacDCopy(pDst,src);
_MacRet(pDst);
}
if (opt==1) {
/* try to _MacRet the per cent */
if(src->dc.id >= 2) {
_MacDCopy(pDst,src);
pDst->dc.id -= 2;
}
else {
(void) ConvLongToDecimal(cons, 100L);
if (!MultiplyDecimal(pDst,src,cons)) {
_MacRet(GM_NULL);
}
}
}
if (opt == 2) {
_MacDCopy(pDst,src);
if (src->dc.id <= GM_MAXID-2) {
pDst->dc.id += 2;
}
else {
if (pDst->dc.id == GM_MAXID-1) {
pDst->dc.id++;
_DivUnsArrByUns( pDst->dc.sl,
10, 5);
}
else
_DivUnsArrByUns( pDst->dc.sl,
100, 5);
if (_MacIsDecZ(pDst))
_MacErr(GM_UNDERFLOW);
}
}
if (opt == 3) {
(void) ConvLongToDecimal(cons, 1200L);
(void) DivideDecimal(pDst, src, cons);
}
_MacRet(pDst);
}