campo-sirio/gfm/dtoul.c

59 lines
918 B
C
Raw Normal View History

/* unsigned long dtoul(x)
*
* ARGUMENT
* DEC *x;
*
* DESCRIPTION
* Converts a DEC to an unsigned long.
*
* SIDE EFFECTS
* None.
*
* RETURNS
* The long 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"
unsigned long ConvDecimalToUnsLong(x)
DEC *x;
{
DEC t;
DEC *pt;
unsigned long i;
_MacStart(GM_DTOUL);
_MacInVar(x, 0L);
pt=&t;
(void) _ScaleDec80Bit(pt, x, 0);
/* 0 <= x < 2^32 */
if (!_MacIsDecN(pt) && (pt->ls.lsl[1] == 0) && (pt->dc.msd == 0)) {
if (CompareDecimal(pt,x)!=0)
_MacErr(GM_CNVRW);
i = pt->ls.lsl[0];
_MacRet (i);
}
/* overflow */
_MacErr(GM_CNVRE);
_MacRet((unsigned) 0L);
}