campo-sirio/gfm/ddivr.c

76 lines
1.4 KiB
C
Raw Normal View History

/* DEC *DivideDecimalAndRound(dst,src1,src2,nid);
*
* ARGUMENT
* DEC *dst;
* DEC *src1,*src2;
* int nid;
*
* DESCRIPTION
* Divides src1 by src2, storing the result in dst. The quotient is
* calculated to nid decimal places.
*
* RETURNS
* Returns pointer to dst 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_NOMEMORY
* GM_OVERFLOW
* GM_UNDERFLOW
* GM_DIV0
* GM_INVALIDID
*
* 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 *DivideDecimalAndRound(dst,src1,src2,nid)
DEC *dst;
DEC *src1,*src2;
int nid;
{
int i;
_MacStart(GM_DDIVR);
_MacInVarD(src1);
_MacInVarD(src2);
_MacOutVarD(dst);
if ((nid > GM_MAXID) || (nid < GM_MINID)){
_MacErr(GM_INVALIDID);
_MacRet (GM_NULL);
}
if (_MacIsDecZ(src2)) {
_MacErr(GM_DIV0);
_MacRet(GM_NULL);
}
i = _DivRndDec80Bit(dst, src1, src2, nid);
/* check if number can fit into 64 bits (no shifting allowed) */
if (!((dst->dc.msd == 0) && (dst->dc.sl[3] < 32768L)))
i = GM_OVERFLOW;
if (i != GM_SUCCESS) {
_MacErr(i);
if (i != GM_UNDERFLOW) {
_MacRet(GM_NULL);
}
}
_MacRet(dst);
}