campo-sirio/gfm/dtrunc.c
alex ba237a9d91 Patch level : no patch
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
2002-02-26 12:19:02 +00:00

80 lines
1.7 KiB
C
Executable File

/* DEC *TruncateDecimal(pDst,pSrc1,wID)
*
* ARGUMENT
* pDst is a pointer to the destination DEC structure.
* pSrc1 is a ptr to the source1 DEC structure.
* wID is the integer specifying location of implied decimal
* for the conversion.
*
* DESCRIPTION
* Adjusts the number in pSrc1 (if necessary) while copying it to
* pDst adjusting pDst to wID number of decimal places. If pDst is null
* on entry, tries to first create a pDst, then the conversion. When the
* number of decimal places decreases, the result is truncated (rounded
* towards zero).
*
* SIDE EFFECTS
* pSrc1 remains unchanged and pDst is undefined on error.
*
* RETURNS
* Returns a pointer to the pDst structure unless error,
* in which case it returns a NULL(a C false). On error, the error
* is in wGMError, unless an error was already there.
*
* POSSIBLE ERROR CODES
*
* GM_NULLPOINTER
* GM_INVALIDID
* GM_OVERFLOW
* GM_UNDERFLOW
*
* AUTHOR
* Jared Levy 5/28/87
* Copyright (C) 1987-1990 Greenleaf Software Inc. All rights reserved.
*
* MODIFICATIONS
*
*/
#include <stdio.h>
#include "gm.h"
#include "gmsystem.h"
DEC *TruncateDecimal(pDst,pSrc1,wID)
DEC *pDst, *pSrc1;
int wID;
{
int i;
_MacStart(GM_DTRUNC);
_MacInVarD(pSrc1);
_MacOutVarD(pDst);
if (wID<GM_MINID || wID>GM_MAXID) {
_MacErr(GM_INVALIDID);
_MacRet(GM_NULL);
}
if(_MacIsDecZ(pSrc1)) {
_MacDZero(pDst);
pDst->dc.id = wID;
_MacRet(pDst);
}
i = _TruncateDec80Bit(pDst, pSrc1, wID);
/* 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);
}