Esempio n. 1
0
/*
 *      getnum - get a number from input.
 *
 *      getnum handles all of the numeric input. it accepts
 *      decimal, octal, hexidecimal, and floating point numbers.
 */
getnum()
{       register int    i;
        i = 0;
        if(lastch == '0') {
                getch();
                if(lastch == 'x' || lastch == 'X') {
                        getch();
                        getbase(16);
                        }
                else getbase(8);
                }
        else    {
                getbase(10);
                if(lastch == '.') {
                        getch();
                        rval = ival;    /* float the integer part */
                        getfrac();      /* add the fractional part */
                        lastst = rconst;
                        }
                if(lastch == 'e' || lastch == 'E') {
                        getch();
                        getexp();       /* get the exponent */
                        }
                }
}
Esempio n. 2
0
/*
 *      getnum - get a number from input.
 *
 *      getnum handles all of the numeric input. it accepts
 *      decimal, octal, hexidecimal, and floating point numbers.
 */
void getnum()
{       register int    i;
        i = 0;
        
        ival = 0;
        rval = 0.0;
		Float128::Assign(&rval128,Float128::Zero());
        numstrptr = &numstr[0];
         *numstrptr = lastch;
         numstrptr++; 
        if(lastch == '0') {
                getch();
                if (lastch=='.')
                     goto j1;
                if(lastch == 'x' || lastch == 'X') {
                        getch();
                        getbase(16);
                        }
                else getbase(8);
                }
        else    {
                getbase(10);
j1:
                if(lastch == '.') {
                        getch();
                        rval = (double)ival;    /* float the integer part */
						Float128::IntToFloat(&rval128, (__int64)ival);
                        getfrac();      /* add the fractional part */
                        lastst = rconst;
                        }
                if(lastch == 'e' || lastch == 'E') {
                        getch();
                        getexp();       /* get the exponent */
						// This must be reset because getting the exponent
						// calls getbase() which will set lastst=iconst
						lastst = rconst;
                        }
				
				if (lastst==rconst && (lastch=='Q' || lastch=='q' ||
					lastch=='D' || lastch=='d' || lastch=='s' || lastch=='S' || lastch=='T' || lastch=='t')) {
						float_precision = tolower(lastch);
						getch();
				}
				else
					float_precision = 't';
				
				// Ignore 'U' unsigned suffix
				if (lastch=='U' || lastch=='u') {
					getch();
				}
				}
    numstrptr[-1]='\0';
    numstrptr = NULL;
//    dd_real::read(numstr,rval);
//    printf("leave getnum=%s\r\n", numstr);
				
}
int float2int(float fl) {
	U u;
	int number = 0;
	u.f = fl;

	unsigned int s=getsig(u.i),e = getexp(u.i) - 127,frac = getfrac(u.i);
	
	if(fl == 0 || e & 0x80) return 0;	// Quando o valor passado for zero, ou quando o expoente for negativo, retornar 0 (no caso do expoente negativo, aproximar para zero)
	
	if(e > 30 && !s) {	// Se o expoente é maior 30 e o número não é negativo, é um caso de overflow
		printf("Overflow!!!");
		return -1;	// Retorna código -1 quando dá overflow
	}
	if((s != 0 && e == 31 && frac) || e > 31) {	// Se o número é negativo, sua mantissa não é zero, e o expoente é maior que 30, é um caso de overflow
		printf("Overflow!!!");
		return -1;	// Retorna código -1 quando dá overflow
	}

	number |= 1 << (e);
	
	if(e < 23) {
		number |= frac >> (23 - e);
	}
Esempio n. 4
0
/*
 *      getnum - get a number from input.
 *
 *      getnum handles all of the numeric input. it accepts
 *      decimal, octal, hexidecimal, and floating point numbers.
 */
void getnum(void)
{
    int isfloat = FALSE;
    char *ptr = intstring;

    while (isxdigit(lastch) || lastch == 'x' || lastch == 'X')
    {
        *ptr++ = lastch;
        getch();
    }
    if (lastch == '.')
    {
        isfloat = TRUE;
        *ptr++ = lastch;
        getch();
        while (isdigit(lastch))
        {
            *ptr++ = lastch;
            getch();
        }
    }
    if (lastch == 'e' || lastch == 'E')
    {
        isfloat = TRUE;
        *ptr++ = lastch;
        getch();
        if (lastch == '+' || lastch == '-')
        {
            *ptr++ = lastch;
            getch();
        }
        while (isdigit(lastch))
        {
            *ptr++ = lastch;
            getch();
        }
    }
    if (lastch == 'F')
    {
        isfloat = TRUE;
    }
    *ptr = 0;
    ptr = intstring;
    if (!isfloat)
    {
        if (*ptr == '0')
        {
            ptr++;
            if (*ptr == 'x' ||  *ptr == 'X')
            {
                ptr++;
                getbase(16, &ptr);
            }
            else
                getbase(8, &ptr);
        }
        else
            getbase(10, &ptr);
        if (lastch == 'U' || lastch == 'u')
        {
            lastst = iuconst;
            getch();
            if (lastch == 'L' || lastch == 'l')
            {
                lastst = luconst;
                getch();
            }
        }
        else if (lastch == 'L' || lastch == 'l')
        {
            lastst = lconst;
            getch();
            if (lastch == 'U' || lastch == 'u')
            {
                lastst = luconst;
                getch();
            }
        }
    }
    else
    {
        getbase(10, &ptr);
        if (*ptr == '.')
        {
            ptr++;
            rval = ival; /* float the integer part */
            getfrac(&ptr); /* add the fractional part */
            lastst = rconst;
        }
        if (*ptr == 'e' ||  *ptr == 'E')
        {
            ptr++;
            getexp(&ptr); /* get the exponent */
        }
        if (lastch == 'F' || lastch == 'f')
        {
            if (lastst != rconst)
            {
                rval = ival;
            }
            lastst = fconst;
            getch();
        }
        else if (lastch == 'L' || lastch == 'l')
        {
            if (lastst != rconst)
            {
                rval = ival;
            }
            lastst = lrconst;
            getch();
        }
    }
}
Esempio n. 5
0
double ParseValueUnitString(BSTR s, int* punitType)
{
	BSTR p = s;

// get sign
	int sign = 1;

	if ((*p == L'-') || (*p == L'+'))
	{
		if (*p == L'-') sign = -1;
		p++;
	}

// get number
	long integer = getnumber(&p);

// get fraction
	double fraction;
	if (*p == L'.' || *p == L',')
	{
		p++;
		fraction = getfrac(&p);
	}
	else
		fraction = 0;

	double specifiedValue = integer + fraction;
	if (sign == -1) specifiedValue = -specifiedValue;

	/*
	if (p[0] == L'p' && p[1] == L'x' && p[2] == 0)
		*punitType = CSS_PX;
		*/

	else if (p[0] == L'i' && p[1] == L'n' && p[2] == 0)
		*punitType = CSS_IN;

	else if (p[0] == L'm' && p[1] == L'm' && p[2] == 0)
		*punitType = CSS_MM;

	else if (p[0] == L'c' && p[1] == L'm' && p[2] == 0)
		*punitType = CSS_CM;

	else if (p[0] == L'p' && p[1] == L't' && p[2] == 0)
		*punitType = CSS_PT;

	else if (p[0] == L'p' && p[1] == L'c' && p[2] == 0)
		*punitType = CSS_PC;
/*
	else if (p[0] == L'p' && p[1] == L'c' && p[2] == 0)
		*punitType = CSS_EMS;

	else if (p[0] == L'e' && p[1] == L'm' && p[2] == 0)
		*punitType = CSS_EXS;
*/

	/*
	else if (p[0] == L'%' && p[1] == 0)
		*punitType = CSS_PERCENTAGE;
*/
	else if (p[0] == 0)
		*punitType = CSS_NUMBER;

	else
		*punitType = 0;//CSS_UNKNOWN; // ??

	return specifiedValue;
}