* Copyright (c) 1982 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
* @(#)asnumber.h 5.1 (Berkeley) 4/30/85
union Il_int
{ /* long word */
union Iq_int
{ /* quad word */
union Io_int
{ /* octal word */
union Ff_float numFf_float
;
union Fd_float numFd_float
;
union Fg_float numFg_float
;
union Fh_float numFh_float
;
char num_tag
; /* the key field: TYPB..TYPUNPACKED */
char num_sign
; /* when unpacked, the sign */
short num_exponent
; /* when unpacked, the unexcessed exp */
typedef struct as_number Bignum
;
extern Bignum Znumber
; /* one all zero'ed out */
#define num_uchar num_num.numIq_int.Iq_uchar
#define num_uint num_num.numIq_int.Iq_ulong
#define num_ulong num_num.numIq_int.Iq_ulong
#define num_ushort num_num.numIq_int.Iq_ushort
* The following definitions must all be consistent.
* They define the granularity of working on longs, quad and octal
* words. Currently, the granularity is as large as it can be: 32 bits
#define CH_N 4 /* number of pieces */
#define CH_BITS 32 /* number of bits per piece */
#define CH_FIELD(x) ((x).num_num.numIo_int.Io_ulong)
typedef u_int
*chptr
; /* basic data type */
#define SIGNBIT 0x80000000
#define HOC (CH_N - 1) /* high order chunk */
#define MAXINT_1 ((unsigned)(1<<(CH_BITS - 1)))
#define MAXINT_10 ((unsigned)((MAXINT_1/(unsigned)10)))
#define MAXINT_5 ((unsigned)((MAXINT_1/(unsigned)5)))
* These values were computed using dc, so are exact.
* Only MAXINT_10 and MAXINT_5 are used in the programs.
#define MAXINT_1 2147483648
#define MAXINT_10 214748364
#define MAXINT_5 429496729
Bignum
as_atoi(); /* converts string to integer */
Bignum
as_atof(); /* converts string to float */
Bignum
bigatof(); /* converts string to float */
Bignum
floatconvert(); /* converts amongst float #s */
Bignum
intconvert(); /* converts amongst float #s */
Bignum
bignumconvert(); /* converts amongst float #s */
Bignum
bignumpack(); /* converts UNPACKED bignum to bignum */
Bignum
bignumunpack(); /* converts bignum to UNPACKED bignum */
* Definitions for overflows.
#define OVF_ADDV (1<<0) /* integer: adding two vectors overflowed */
#define OVF_LSHIFT (1<<1) /* integer: left shifting a vector lost bits */
#define OVF_POSOVF (1<<2) /* integer: positive number overflowed */
#define OVF_MAXINT (1<<3) /* integer: the number was the maxint + 1*/
#define OVF_F (1<<4) /* float: F overflow */
#define OVF_D (1<<5) /* float: D overflow */
#define OVF_G (1<<6) /* float: G overflow */
#define OVF_H (1<<7) /* float: H overflow */
#define OVF_OVERFLOW (1<<9) /* overflow in conversion */
#define OVF_UNDERFLOW (1<<10) /* underflow in conversion */
* Definitions to unpack big numbers numbers into
* a 128 bit fraction and 16 bit excess-free exponent,
* and an 8 copy bits for the sign.
* The fraction is represented as a normalized binary number,
* 128 bits long, with the binary point between bits 127 and the
* hypothetical 128'th bit. This hypothetical 128'th bit
* is always assumed to be one.
* A map entry is NOTAKE if the corresponding byte is
* The maps are for going from packed to unpacked format (b_up)
* and from unpacked to packed format (b_p)
* for the mantissa (b_upmmap) and for the exponent(b_upemap)
* byte #i in the packed number goes to byte #b_upmmap[i] in the unpacked
char b_upmmap
[16]; /* byte x of float goes to up_mmap[x] in mant */
char b_pmmap
[16]; /* inverse of upmmap */
char b_upemap
[2]; /* byte x of float goes to up_emap[x] in exp */
char b_pemap
[2]; /* inverse of upemap */
char b_mlshift
; /* left shift quantity to justify to left */
char b_ershift
; /* right shift quantity to r justify exponent */
short b_msigbits
; /* # sig bits in mantissa */
char b_esigbits
; /* # sig bits in exponent */
short b_eexcess
; /* exponent excess */
extern struct ty_bigdesc ty_bigdesc
[];
#define ONES(n) ((1 << (n)) - 1)
#define assert(x, str) if (!(x)) panic("%s%s\n", "x", str)