xref: /csrg-svn/old/as.vax/asnumber.h (revision 19826)
15816Srrh /*
2*19826Sdist  * Copyright (c) 1982 Regents of the University of California.
3*19826Sdist  * All rights reserved.  The Berkeley software License Agreement
4*19826Sdist  * specifies the terms and conditions for redistribution.
5*19826Sdist  *
6*19826Sdist  *	@(#)asnumber.h	5.1 (Berkeley) 04/30/85
75816Srrh  */
85816Srrh 
95816Srrh union Ib_int{		/* byte */
105816Srrh 	u_char	Ib_uchar[1];
115816Srrh 	char	Ichar;
125816Srrh };
135816Srrh union Iw_int{		/* word */
145816Srrh 	u_char	Iw_uchar[2];
155816Srrh 	u_short	Iw_ushort[1];
165816Srrh 	short	Iw_short;
175816Srrh };
185816Srrh union Il_int{		/* long word */
195816Srrh 	u_char	Il_uchar[4];
205816Srrh 	u_short	Il_ushort[2];
215816Srrh 	u_int	Il_ulong[1];
225816Srrh 	int	Il_long;
235816Srrh };
245816Srrh 
255816Srrh union Iq_int{		/* quad word */
265816Srrh 	u_char	Iq_uchar[8];
275816Srrh 	u_short	Iq_ushort[4];
285816Srrh 	u_int	Iq_ulong[2];
295816Srrh };
305816Srrh 
315816Srrh union Io_int{		/* octal word */
325816Srrh 	u_char	Io_uchar[16];
335816Srrh 	u_short	Io_ushort[8];
345816Srrh 	u_int	Io_ulong[4];
355816Srrh 	union	Iq_int	Io_quad[2];
365816Srrh };
375816Srrh 
385816Srrh union Ff_float{
395816Srrh 	u_char	Ff_uchar[4];
405816Srrh 	u_short	Ff_ushort[2];
415816Srrh 	u_int	Ff_ulong[1];
425816Srrh 	float	Ff_value;
435816Srrh };
445816Srrh 
455816Srrh union Fd_float{
465816Srrh 	u_char	Fd_uchar[8];
475816Srrh 	u_short	Fd_ushort[4];
485816Srrh 	u_int	Fd_ulong[2];
495816Srrh 	double	Fd_value;
505816Srrh };
515816Srrh 
525816Srrh union Fg_float{
535816Srrh 	u_char	Fg_uchar[8];
545816Srrh 	u_short	Fg_ushort[4];
555816Srrh 	u_int	Fg_ulong[2];
565816Srrh };
575816Srrh 
585816Srrh union Fh_float{
595816Srrh 	u_char	Fh_uchar[16];
605816Srrh 	u_short	Fh_ushort[8];
615816Srrh 	u_int	Fh_ulong[4];
625816Srrh };
635816Srrh 
645816Srrh struct	as_number{
655816Srrh 	union {
665816Srrh 		union Ib_int	numIb_int;
675816Srrh 		union Iw_int	numIw_int;
685816Srrh 		union Il_int	numIl_int;
695816Srrh 		union Iq_int	numIq_int;
705816Srrh 		union Io_int	numIo_int;
715816Srrh 		union Ff_float	numFf_float;
725816Srrh 		union Fd_float	numFd_float;
735816Srrh 		union Fg_float	numFg_float;
745816Srrh 		union Fh_float	numFh_float;
755816Srrh 	}num_num;
765816Srrh 	char	num_tag;		/* the key field: TYPB..TYPUNPACKED */
775816Srrh 	char	num_sign;		/* when unpacked, the sign */
785816Srrh 	short	num_exponent;		/* when unpacked, the unexcessed exp */
795816Srrh };
805816Srrh typedef	struct as_number	Bignum;
815816Srrh 
825816Srrh extern	Bignum	Znumber;		/* one all zero'ed out */
835816Srrh 
845816Srrh #define	num_uchar	num_num.numIq_int.Iq_uchar
855816Srrh #define	num_uint	num_num.numIq_int.Iq_ulong
865816Srrh #define	num_ulong	num_num.numIq_int.Iq_ulong
875816Srrh #define	num_ushort	num_num.numIq_int.Iq_ushort
885816Srrh /*
895816Srrh  *	The following definitions must all be consistent.
905816Srrh  *	They define the granularity of working on longs, quad and octal
915816Srrh  *	words. Currently, the granularity is as large as it can be: 32 bits
925816Srrh  *	in a chunk.
935816Srrh  */
945816Srrh #define	CH_N		4		/* number of pieces */
955816Srrh #define	CH_BITS		32		/* number of bits per piece */
965816Srrh #define	CH_FIELD(x)	((x).num_num.numIo_int.Io_ulong)
975816Srrh typedef	u_int		*chptr;		/* basic data type */
985816Srrh #define SIGNBIT		0x80000000
995816Srrh 
1005816Srrh #define	HOC		(CH_N - 1)	/* high order chunk */
1015816Srrh #if 0
1025816Srrh #define	MAXINT_1	((unsigned)(1<<(CH_BITS - 1)))
1035816Srrh #define	MAXINT_10	((unsigned)((MAXINT_1/(unsigned)10)))
1045816Srrh #define	MAXINT_5	((unsigned)((MAXINT_1/(unsigned)5)))
1055816Srrh #else not 0
1065816Srrh /*
1075816Srrh  *	These values were computed using dc, so are exact.
1085816Srrh  *	Only MAXINT_10 and MAXINT_5 are used in the programs.
1095816Srrh  */
1105816Srrh #define	MAXINT_1	2147483648
1115816Srrh #define	MAXINT_10	214748364
1125816Srrh #define	MAXINT_5	429496729
1135816Srrh #endif not 0
1145816Srrh 
1155816Srrh Bignum as_atoi();		/* converts string to integer */
1165816Srrh Bignum as_atof();		/* converts string to float */
1175816Srrh Bignum bigatof();		/* converts string to float */
1185816Srrh Bignum floatconvert();	/* converts amongst float #s */
1195816Srrh Bignum intconvert();		/* converts amongst float #s */
1205816Srrh Bignum bignumconvert();	/* converts amongst float #s */
1215816Srrh Bignum bignumpack();		/* converts UNPACKED bignum to bignum */
1225816Srrh Bignum bignumunpack();	/* converts bignum to UNPACKED bignum */
1235816Srrh 
1245816Srrh /*
1255816Srrh  *	Definitions for overflows.
1265816Srrh  */
1275816Srrh typedef	u_int	Ovf;
1285816Srrh 
1295816Srrh #define	OVF_ADDV	(1<<0)	/* integer: adding two vectors overflowed */
1305816Srrh #define	OVF_LSHIFT	(1<<1)	/* integer: left shifting a vector lost bits */
1315816Srrh #define	OVF_POSOVF	(1<<2)	/* integer: positive number overflowed */
1325816Srrh #define	OVF_MAXINT	(1<<3)	/* integer: the number was the maxint + 1*/
1335816Srrh #define	OVF_F		(1<<4)	/* float: F overflow */
1345816Srrh #define	OVF_D		(1<<5)	/* float: D overflow */
1355816Srrh #define	OVF_G		(1<<6)	/* float: G overflow */
1365816Srrh #define	OVF_H		(1<<7)	/* float: H overflow */
1375816Srrh #define	OVF_OVERFLOW	(1<<9)	/* overflow in conversion */
1385816Srrh #define	OVF_UNDERFLOW	(1<<10)	/* underflow in conversion */
1395816Srrh 
1405816Srrh Ovf	posovf();
1415816Srrh Ovf	numclear();
1425816Srrh Ovf	numshift();
1435816Srrh Ovf	numaddv();
1445816Srrh Ovf	numaddd();
1455816Srrh Ovf	num1comp();
1465816Srrh Ovf	numnegate();
1475816Srrh 
1485816Srrh /*
1495816Srrh  *	Definitions to unpack big numbers numbers into
1505816Srrh  *	a 128 bit fraction and 16 bit excess-free exponent,
1515816Srrh  *	and an 8 copy bits for the sign.
1525816Srrh  *
1535816Srrh  *	The fraction is represented as a normalized binary number,
1545816Srrh  *	128 bits long, with the binary point between bits 127 and the
1555816Srrh  *	hypothetical 128'th bit.  This hypothetical 128'th bit
1565816Srrh  *	is always assumed to be one.
1575816Srrh  */
1585816Srrh /*
1595816Srrh  *	A map entry is NOTAKE if the corresponding byte is
1605816Srrh  *	not to be taken
1615816Srrh  *
1625816Srrh  *	The maps are for going from packed to unpacked format (b_up)
1635816Srrh  *	and from unpacked to packed format (b_p)
1645816Srrh  *	for the mantissa (b_upmmap) and for the exponent(b_upemap)
1655816Srrh  *
1665816Srrh  *	byte #i in the packed number goes to byte #b_upmmap[i] in the unpacked
1675816Srrh  */
1685816Srrh #define	NOTAKE	-1
1695816Srrh struct ty_bigdesc{
1705816Srrh 	char	b_upmmap[16];	/* byte x of float goes to up_mmap[x] in mant */
1715816Srrh 	char	b_pmmap[16];	/* inverse of upmmap */
1725816Srrh 	char	b_upemap[2];	/* byte x of float goes to up_emap[x] in exp */
1735816Srrh 	char	b_pemap[2];	/* inverse of upemap */
1745816Srrh 	char	b_mlshift;	/* left shift quantity to justify to left */
1755816Srrh 	char	b_ershift;	/* right shift quantity to r justify exponent */
1765816Srrh 	short	b_msigbits;	/* # sig bits in mantissa */
1775816Srrh 	char	b_esigbits;	/* # sig bits in exponent */
1785816Srrh 	short	b_eexcess;	/* exponent excess */
1795816Srrh };
1805816Srrh extern struct ty_bigdesc ty_bigdesc[];
1815816Srrh /*
1825816Srrh  *	Bit manipulations
1835816Srrh  */
1845816Srrh #define	ONES(n)	((1 << (n)) - 1)
1855816Srrh /*
1865816Srrh  *	Assertions
1875816Srrh  */
1885816Srrh #if 1
1895816Srrh #define	assert(x, str) if (!(x)) panic("%s%s\n", "x", str)
1905816Srrh #else
1915816Srrh #define assert(x, str)
1925816Srrh #endif
193