campo-sirio/gfm/dtol.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

84 lines
1.7 KiB
C
Executable File

/* long ConvDecimalToLong(x)
*
* ARGUMENT
* DEC *x;
*
* DESCRIPTION
* Converts a DEC to a long.
*
* SIDE EFFECTS
* None.
*
* RETURNS
* The integer if the conversion is successful, and the error code
* otherwise.
*
* POSSIBLE ERROR CODES
*
* GM_NULLPOINTER
* GM_CNVRE
* GM_CNVRW
*
* AUTHOR
* Jared Levy Feb. 9, 1987
* Copyright (C) 1987-1990 Greenleaf Software Inc. All rights reserved.
*
* MODIFICATIONS
*
*/
#include <stdio.h>
#include "gm.h"
#include "gmsystem.h"
long ConvDecimalToLong(x)
DEC *x;
{
DEC temp;
DEC *pt=&temp, dn, *n=&dn;
mbool wfIsNeg;
long l;
unsigned long maxpos=2147483647L;
_MacStart(GM_DTOL);
_MacInVar(x, 0L);
_MacDCopy(n, x);
/*
* The following two lines of code shouldn't be separated. I ran into
* a problem with Zortech v2.06. If the _ScaleDec80Bit is called right
* after executing _MacIsDecN, the 0 in the parameter list sometimes
* gets changed to a -1. This is bad. Expect Zortech to fix it someday,
* but since I only had to change the order of execution of these three
* lines, no need to change. Same problem is found in DTOL.C.
*/
(void) _ScaleDec80Bit(pt, n, 0); /* convert to integer format */
wfIsNeg = _MacIsDecN(n);
/* |x| < 2147483648 */
if ((pt->ls.lsl[1] == 0) && !(pt->ls.lsl[0] & 0x80000000/*UL*/)
&& (pt->dc.msd == 0)) {
l = (long) (pt->ls.lsl[0]);
if (CompareDecimal(n,pt)!=0)
_MacErr(GM_CNVRW);
if (wfIsNeg)
{_MacRet(-l)}
else
_MacRet(l);
}
/* check for -2147483648 AND "logical" _MacRet to get by MSC bug*/
if (wfIsNeg && (pt->ls.lsl[0] == 0x80000000L) &&
(pt->ls.lsl[1] == 0) && (pt->ls.lmsd == 0)) {
if (CompareDecimal(n,pt)!=0)
_MacErr(GM_CNVRW);
_MacRet((long) ~maxpos);
}
/* overflow */
_MacErr(GM_CNVRE);
_MacRet(0L);
}