1*40587Sbostic /* 2*40587Sbostic * Copyright (c) 1982 Regents of the University of California 3*40587Sbostic * @(#)asnumber.h 4.3 2/14/82 4*40587Sbostic */ 5*40587Sbostic 6*40587Sbostic union Ib_int{ /* byte */ 7*40587Sbostic u_char Ib_uchar[1]; 8*40587Sbostic char Ichar; 9*40587Sbostic }; 10*40587Sbostic union Iw_int{ /* word */ 11*40587Sbostic u_char Iw_uchar[2]; 12*40587Sbostic u_short Iw_ushort[1]; 13*40587Sbostic short Iw_short; 14*40587Sbostic }; 15*40587Sbostic union Il_int{ /* long word */ 16*40587Sbostic u_char Il_uchar[4]; 17*40587Sbostic u_short Il_ushort[2]; 18*40587Sbostic u_int Il_ulong[1]; 19*40587Sbostic int Il_long; 20*40587Sbostic }; 21*40587Sbostic 22*40587Sbostic union Iq_int{ /* quad word */ 23*40587Sbostic u_char Iq_uchar[8]; 24*40587Sbostic u_short Iq_ushort[4]; 25*40587Sbostic u_int Iq_ulong[2]; 26*40587Sbostic }; 27*40587Sbostic 28*40587Sbostic 29*40587Sbostic union Ff_float{ 30*40587Sbostic u_char Ff_uchar[4]; 31*40587Sbostic u_short Ff_ushort[2]; 32*40587Sbostic u_int Ff_ulong[1]; 33*40587Sbostic float Ff_value; 34*40587Sbostic }; 35*40587Sbostic 36*40587Sbostic union Fd_float{ 37*40587Sbostic u_char Fd_uchar[8]; 38*40587Sbostic u_short Fd_ushort[4]; 39*40587Sbostic u_int Fd_ulong[2]; 40*40587Sbostic double Fd_value; 41*40587Sbostic }; 42*40587Sbostic 43*40587Sbostic 44*40587Sbostic struct as_number{ 45*40587Sbostic union { 46*40587Sbostic union Ib_int numIb_int; 47*40587Sbostic union Iw_int numIw_int; 48*40587Sbostic union Il_int numIl_int; 49*40587Sbostic union Iq_int numIq_int; 50*40587Sbostic union Ff_float numFf_float; 51*40587Sbostic union Fd_float numFd_float; 52*40587Sbostic }num_num; 53*40587Sbostic char num_tag; /* the key field: TYPB..TYPUNPACKED */ 54*40587Sbostic char num_sign; /* the sign */ 55*40587Sbostic short num_exponent; /* the unexcessed exp */ 56*40587Sbostic }; 57*40587Sbostic typedef struct as_number Bignum; 58*40587Sbostic 59*40587Sbostic extern Bignum Znumber; /* one all zero'ed out */ 60*40587Sbostic 61*40587Sbostic #define num_uchar num_num.numIq_int.Iq_uchar 62*40587Sbostic #define num_uint num_num.numIq_int.Iq_ulong 63*40587Sbostic #define num_ulong num_num.numIq_int.Iq_ulong 64*40587Sbostic #define num_ushort num_num.numIq_int.Iq_ushort 65*40587Sbostic /* 66*40587Sbostic * The following definitions must all be consistent. 67*40587Sbostic * They define the granularity of working on longs and quad 68*40587Sbostic * words. Currently, the granularity is as large as it can be: 32 bits 69*40587Sbostic * in a chunk. 70*40587Sbostic */ 71*40587Sbostic #define CH_N 2 /* number of pieces */ 72*40587Sbostic #define CH_BITS 32 /* number of bits per piece */ 73*40587Sbostic #define CH_FIELD(x) ((x).num_num.numIq_int.Iq_ulong) 74*40587Sbostic typedef u_int *chptr; /* basic data type */ 75*40587Sbostic #define SIGNBIT 0x80000000 76*40587Sbostic 77*40587Sbostic #define HOC (CH_N - 1) /* high order chunk */ 78*40587Sbostic #if 0 79*40587Sbostic #define MAXINT_1 ((unsigned)(1<<(CH_BITS - 1))) 80*40587Sbostic #define MAXINT_10 ((unsigned)((MAXINT_1/(unsigned)10))) 81*40587Sbostic #define MAXINT_5 ((unsigned)((MAXINT_1/(unsigned)5))) 82*40587Sbostic #else not 0 83*40587Sbostic /* 84*40587Sbostic * These values were computed using dc, so are exact. 85*40587Sbostic * Only MAXINT_10 and MAXINT_5 are used in the programs. 86*40587Sbostic */ 87*40587Sbostic #define MAXINT_1 2147483648 88*40587Sbostic #define MAXINT_10 214748364 89*40587Sbostic #define MAXINT_5 429496729 90*40587Sbostic #endif not 0 91*40587Sbostic 92*40587Sbostic Bignum as_atoi(); /* converts string to integer */ 93*40587Sbostic Bignum as_atof(); /* converts string to float */ 94*40587Sbostic 95*40587Sbostic /* 96*40587Sbostic * Definitions for overflows. 97*40587Sbostic */ 98*40587Sbostic typedef u_int Ovf; 99*40587Sbostic 100*40587Sbostic #define OVF_ADDV (1<<0) /* integer: adding two vectors overflowed */ 101*40587Sbostic #define OVF_LSHIFT (1<<1) /* integer: left shifting a vector lost bits */ 102*40587Sbostic #define OVF_POSOVF (1<<2) /* integer: positive number overflowed */ 103*40587Sbostic #define OVF_MAXINT (1<<3) /* integer: the number was the maxint + 1*/ 104*40587Sbostic #define OVF_F (1<<4) /* float: F overflow */ 105*40587Sbostic #define OVF_D (1<<5) /* float: D overflow */ 106*40587Sbostic #define OVF_OVERFLOW (1<<9) /* overflow in conversion */ 107*40587Sbostic #define OVF_UNDERFLOW (1<<10) /* underflow in conversion */ 108*40587Sbostic 109*40587Sbostic Ovf posovf(); 110*40587Sbostic Ovf numclear(); 111*40587Sbostic Ovf numshift(); 112*40587Sbostic Ovf numaddv(); 113*40587Sbostic Ovf numaddd(); 114*40587Sbostic Ovf num1comp(); 115*40587Sbostic Ovf numnegate(); 116*40587Sbostic /* 117*40587Sbostic * Bit manipulations 118*40587Sbostic */ 119*40587Sbostic #define ONES(n) ((1 << (n)) - 1) 120*40587Sbostic /* 121*40587Sbostic * Assertions 122*40587Sbostic */ 123*40587Sbostic #if 1 124*40587Sbostic #define assert(x, str) if (!(x)) panic("%s%s\n", "x", str) 125*40587Sbostic #else 126*40587Sbostic #define assert(x, str) 127*40587Sbostic #endif 128