xref: /csrg-svn/old/as.vax/asnumber.h (revision 5816)
1*5816Srrh /*
2*5816Srrh  *	Copyright (c) 1982 Regents of the University of California
3*5816Srrh  *	@(#)asnumber.h 4.1 02/14/82
4*5816Srrh  */
5*5816Srrh 
6*5816Srrh union Ib_int{		/* byte */
7*5816Srrh 	u_char	Ib_uchar[1];
8*5816Srrh 	char	Ichar;
9*5816Srrh };
10*5816Srrh union Iw_int{		/* word */
11*5816Srrh 	u_char	Iw_uchar[2];
12*5816Srrh 	u_short	Iw_ushort[1];
13*5816Srrh 	short	Iw_short;
14*5816Srrh };
15*5816Srrh union Il_int{		/* long word */
16*5816Srrh 	u_char	Il_uchar[4];
17*5816Srrh 	u_short	Il_ushort[2];
18*5816Srrh 	u_int	Il_ulong[1];
19*5816Srrh 	int	Il_long;
20*5816Srrh };
21*5816Srrh 
22*5816Srrh union Iq_int{		/* quad word */
23*5816Srrh 	u_char	Iq_uchar[8];
24*5816Srrh 	u_short	Iq_ushort[4];
25*5816Srrh 	u_int	Iq_ulong[2];
26*5816Srrh };
27*5816Srrh 
28*5816Srrh union Io_int{		/* octal word */
29*5816Srrh 	u_char	Io_uchar[16];
30*5816Srrh 	u_short	Io_ushort[8];
31*5816Srrh 	u_int	Io_ulong[4];
32*5816Srrh 	union	Iq_int	Io_quad[2];
33*5816Srrh };
34*5816Srrh 
35*5816Srrh union Ff_float{
36*5816Srrh 	u_char	Ff_uchar[4];
37*5816Srrh 	u_short	Ff_ushort[2];
38*5816Srrh 	u_int	Ff_ulong[1];
39*5816Srrh 	float	Ff_value;
40*5816Srrh };
41*5816Srrh 
42*5816Srrh union Fd_float{
43*5816Srrh 	u_char	Fd_uchar[8];
44*5816Srrh 	u_short	Fd_ushort[4];
45*5816Srrh 	u_int	Fd_ulong[2];
46*5816Srrh 	double	Fd_value;
47*5816Srrh };
48*5816Srrh 
49*5816Srrh union Fg_float{
50*5816Srrh 	u_char	Fg_uchar[8];
51*5816Srrh 	u_short	Fg_ushort[4];
52*5816Srrh 	u_int	Fg_ulong[2];
53*5816Srrh };
54*5816Srrh 
55*5816Srrh union Fh_float{
56*5816Srrh 	u_char	Fh_uchar[16];
57*5816Srrh 	u_short	Fh_ushort[8];
58*5816Srrh 	u_int	Fh_ulong[4];
59*5816Srrh };
60*5816Srrh 
61*5816Srrh struct	as_number{
62*5816Srrh 	union {
63*5816Srrh 		union Ib_int	numIb_int;
64*5816Srrh 		union Iw_int	numIw_int;
65*5816Srrh 		union Il_int	numIl_int;
66*5816Srrh 		union Iq_int	numIq_int;
67*5816Srrh 		union Io_int	numIo_int;
68*5816Srrh 		union Ff_float	numFf_float;
69*5816Srrh 		union Fd_float	numFd_float;
70*5816Srrh 		union Fg_float	numFg_float;
71*5816Srrh 		union Fh_float	numFh_float;
72*5816Srrh 	}num_num;
73*5816Srrh 	char	num_tag;		/* the key field: TYPB..TYPUNPACKED */
74*5816Srrh 	char	num_sign;		/* when unpacked, the sign */
75*5816Srrh 	short	num_exponent;		/* when unpacked, the unexcessed exp */
76*5816Srrh };
77*5816Srrh typedef	struct as_number	Bignum;
78*5816Srrh 
79*5816Srrh extern	Bignum	Znumber;		/* one all zero'ed out */
80*5816Srrh 
81*5816Srrh #define	num_uchar	num_num.numIq_int.Iq_uchar
82*5816Srrh #define	num_uint	num_num.numIq_int.Iq_ulong
83*5816Srrh #define	num_ulong	num_num.numIq_int.Iq_ulong
84*5816Srrh #define	num_ushort	num_num.numIq_int.Iq_ushort
85*5816Srrh /*
86*5816Srrh  *	The following definitions must all be consistent.
87*5816Srrh  *	They define the granularity of working on longs, quad and octal
88*5816Srrh  *	words. Currently, the granularity is as large as it can be: 32 bits
89*5816Srrh  *	in a chunk.
90*5816Srrh  */
91*5816Srrh #define	CH_N		4		/* number of pieces */
92*5816Srrh #define	CH_BITS		32		/* number of bits per piece */
93*5816Srrh #define	CH_FIELD(x)	((x).num_num.numIo_int.Io_ulong)
94*5816Srrh typedef	u_int		*chptr;		/* basic data type */
95*5816Srrh #define SIGNBIT		0x80000000
96*5816Srrh 
97*5816Srrh #define	HOC		(CH_N - 1)	/* high order chunk */
98*5816Srrh #if 0
99*5816Srrh #define	MAXINT_1	((unsigned)(1<<(CH_BITS - 1)))
100*5816Srrh #define	MAXINT_10	((unsigned)((MAXINT_1/(unsigned)10)))
101*5816Srrh #define	MAXINT_5	((unsigned)((MAXINT_1/(unsigned)5)))
102*5816Srrh #else not 0
103*5816Srrh /*
104*5816Srrh  *	These values were computed using dc, so are exact.
105*5816Srrh  *	Only MAXINT_10 and MAXINT_5 are used in the programs.
106*5816Srrh  */
107*5816Srrh #define	MAXINT_1	2147483648
108*5816Srrh #define	MAXINT_10	214748364
109*5816Srrh #define	MAXINT_5	429496729
110*5816Srrh #endif not 0
111*5816Srrh 
112*5816Srrh Bignum as_atoi();		/* converts string to integer */
113*5816Srrh Bignum as_atof();		/* converts string to float */
114*5816Srrh Bignum bigatof();		/* converts string to float */
115*5816Srrh Bignum floatconvert();	/* converts amongst float #s */
116*5816Srrh Bignum intconvert();		/* converts amongst float #s */
117*5816Srrh Bignum bignumconvert();	/* converts amongst float #s */
118*5816Srrh Bignum bignumpack();		/* converts UNPACKED bignum to bignum */
119*5816Srrh Bignum bignumunpack();	/* converts bignum to UNPACKED bignum */
120*5816Srrh 
121*5816Srrh /*
122*5816Srrh  *	Definitions for overflows.
123*5816Srrh  */
124*5816Srrh typedef	u_int	Ovf;
125*5816Srrh 
126*5816Srrh #define	OVF_ADDV	(1<<0)	/* integer: adding two vectors overflowed */
127*5816Srrh #define	OVF_LSHIFT	(1<<1)	/* integer: left shifting a vector lost bits */
128*5816Srrh #define	OVF_POSOVF	(1<<2)	/* integer: positive number overflowed */
129*5816Srrh #define	OVF_MAXINT	(1<<3)	/* integer: the number was the maxint + 1*/
130*5816Srrh #define	OVF_F		(1<<4)	/* float: F overflow */
131*5816Srrh #define	OVF_D		(1<<5)	/* float: D overflow */
132*5816Srrh #define	OVF_G		(1<<6)	/* float: G overflow */
133*5816Srrh #define	OVF_H		(1<<7)	/* float: H overflow */
134*5816Srrh #define	OVF_OVERFLOW	(1<<9)	/* overflow in conversion */
135*5816Srrh #define	OVF_UNDERFLOW	(1<<10)	/* underflow in conversion */
136*5816Srrh 
137*5816Srrh Ovf	posovf();
138*5816Srrh Ovf	numclear();
139*5816Srrh Ovf	numshift();
140*5816Srrh Ovf	numaddv();
141*5816Srrh Ovf	numaddd();
142*5816Srrh Ovf	num1comp();
143*5816Srrh Ovf	numnegate();
144*5816Srrh 
145*5816Srrh /*
146*5816Srrh  *	Definitions to unpack big numbers numbers into
147*5816Srrh  *	a 128 bit fraction and 16 bit excess-free exponent,
148*5816Srrh  *	and an 8 copy bits for the sign.
149*5816Srrh  *
150*5816Srrh  *	The fraction is represented as a normalized binary number,
151*5816Srrh  *	128 bits long, with the binary point between bits 127 and the
152*5816Srrh  *	hypothetical 128'th bit.  This hypothetical 128'th bit
153*5816Srrh  *	is always assumed to be one.
154*5816Srrh  */
155*5816Srrh /*
156*5816Srrh  *	A map entry is NOTAKE if the corresponding byte is
157*5816Srrh  *	not to be taken
158*5816Srrh  *
159*5816Srrh  *	The maps are for going from packed to unpacked format (b_up)
160*5816Srrh  *	and from unpacked to packed format (b_p)
161*5816Srrh  *	for the mantissa (b_upmmap) and for the exponent(b_upemap)
162*5816Srrh  *
163*5816Srrh  *	byte #i in the packed number goes to byte #b_upmmap[i] in the unpacked
164*5816Srrh  */
165*5816Srrh #define	NOTAKE	-1
166*5816Srrh struct ty_bigdesc{
167*5816Srrh 	char	b_upmmap[16];	/* byte x of float goes to up_mmap[x] in mant */
168*5816Srrh 	char	b_pmmap[16];	/* inverse of upmmap */
169*5816Srrh 	char	b_upemap[2];	/* byte x of float goes to up_emap[x] in exp */
170*5816Srrh 	char	b_pemap[2];	/* inverse of upemap */
171*5816Srrh 	char	b_mlshift;	/* left shift quantity to justify to left */
172*5816Srrh 	char	b_ershift;	/* right shift quantity to r justify exponent */
173*5816Srrh 	short	b_msigbits;	/* # sig bits in mantissa */
174*5816Srrh 	char	b_esigbits;	/* # sig bits in exponent */
175*5816Srrh 	short	b_eexcess;	/* exponent excess */
176*5816Srrh };
177*5816Srrh extern struct ty_bigdesc ty_bigdesc[];
178*5816Srrh /*
179*5816Srrh  *	Bit manipulations
180*5816Srrh  */
181*5816Srrh #define	ONES(n)	((1 << (n)) - 1)
182*5816Srrh /*
183*5816Srrh  *	Assertions
184*5816Srrh  */
185*5816Srrh #if 1
186*5816Srrh #define	assert(x, str) if (!(x)) panic("%s%s\n", "x", str)
187*5816Srrh #else
188*5816Srrh #define assert(x, str)
189*5816Srrh #endif
190