campo-sirio/gfm/dmulr.c

77 lines
1.4 KiB
C
Raw Normal View History

/* DEC *MultiplyDecimalAndRound(pDst,pSrc1,pSrc2,nid);
*
* ARGUMENT
* DEC *pDst;
* DEC *pSrc1,pSrc2;
* int nid;
*
* DESCRIPTION
* Multiplies pSrc1 by pSrc2, storing the result in pDst. The product is
* calculated to nid decimal places.
*
* SIDE EFFECTS
*
* RETURNS
* Returns pointer to pDst if successful, otherwise a GM_NULL. The
* type error (GM_OVERFLOW, GM_UNDERFLOW, GM_NOMEMORY) is in wGMError
* if wGMError doesn't contain a previous error.
*
* POSSIBLE ERROR CODES
*
* GM_NULLPOINTER
* GM_INVALIDID
* GM_OVERFLOW
* GM_UNDERFLOW
*
* AUTHOR
* Jared Levy 05-JAN-1987 17:30
* Copyright (C) 1987-1990 Greenleaf Software Inc. All rights reserved.
*
* MODIFICATIONS
*
*/
#include <stdio.h>
#include "gm.h"
#include "gmsystem.h"
DEC *MultiplyDecimalAndRound(pDst,pSrc1,pSrc2,nid)
DEC *pDst;
DEC *pSrc1,*pSrc2;
int nid;
{
register int i;
_MacStart(GM_DMULR);
if ((nid<GM_MINID) || (nid>GM_MAXID)) {
_MacErr(GM_INVALIDID);
_MacRet(GM_NULL);
}
if (!MultiplyDecimal(pDst, pSrc1, pSrc2))
_MacRet(GM_NULL);
if (_MacIsDecZ(pDst)) {
pDst->dc.id = nid;
_MacRet(pDst);
}
i = _ScaleDec80Bit(pDst, pDst, nid);
/* check if number can fit into 64 bits (no shifting allowed) */
if (!((pDst->dc.msd == 0) && (pDst->dc.sl[3] < 32768L)))
i = GM_OVERFLOW;
if (i != GM_SUCCESS) {
_MacErr(i);
_MacRet(GM_NULL);
}
if (_MacIsDecZ(pDst))
_MacErr(GM_UNDERFLOW);
_MacRet(pDst);
}