diff options
author | Jakob Kaivo <jkk@ung.org> | 2022-03-28 15:46:27 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2022-03-28 15:46:27 -0400 |
commit | 427349ba1556a2efb131ee05f4f3752e35d06957 (patch) | |
tree | e6dcc0f527f5071b8c3e84346521b843a9b21cbd | |
parent | 5a2c4e97e922720bdf86661a28268fa87b57bddd (diff) |
move big.c internal constants to big.c
-rw-r--r-- | big.c | 17 | ||||
-rw-r--r-- | big.h | 22 |
2 files changed, 18 insertions, 21 deletions
@@ -17,6 +17,13 @@ #define MAX_INT_BITS 60 #define LONG_LONG_OVERFLOW (1ll<<MAX_INT_BITS) +#define PTEN 10000 /* largest power of ten < IBASE (used by bigscan) */ +#define PSIXTEEN 4096 /* largest power of sixteen <= IBASE (used by bigtostr) */ +#define PEIGHT 0100000 /* (=32768) largest power of eight <= IBASE (used by bigtostr) */ +#define TENW 4 /* number of factors of 10 in PTEN */ +#define OCTW 5 /* number of factors of 8 in IBASE */ +#define DIGITWIDTH 15 + word big_one; static word big_plus(word, word, int); @@ -116,7 +123,7 @@ word bigplus(word x, word y) word big_plus(word x, word y, int signbit) { word d = digit0(x) + digit0(y); - word r = make(INT, signbit | d & MAXDIGIT, 0); /* result */ + word r = make(INT, signbit | (d & MAXDIGIT), 0); /* result */ word *z = &rest(r); /* pointer to rest of result */ word carry = ((d & IBASE) != 0); @@ -338,7 +345,7 @@ word stimes(word x, word n) word r = make(INT, d & MAXDIGIT, 0); word *y = &rest(r); - while (x = rest(x)) { + while ((x = rest(x)) != 0) { d = n * digit(x) + carry; *y = make(INT, d & MAXDIGIT, 0); y = &rest(*y); @@ -443,7 +450,7 @@ word shortdiv(word x, word n) word q = 0; /* reverse rest(x) into q */ - while (x = rest(x)) { + while ((x = rest(x)) != 0) { q = make(INT, d, q); d = digit(x); /* leaving most sig. digit in d */ } @@ -551,7 +558,7 @@ word longdiv(word x, word y) word len(word x) { word n = 1; - while (x = rest(x)) { + while ((x = rest(x)) != 0) { n++; } @@ -917,7 +924,7 @@ word bigtostr(word x) sign = big_is_negative(x); x1 = make(INT, digit0(x), 0); /* reverse x into x1 */ - while (x = rest(x)) { + while ((x = rest(x)) != 0) { x1 = make(INT, digit(x), x1); } x = x1; @@ -8,12 +8,11 @@ * Revised to C11 standard and made 64bit compatible, January 2020 * *------------------------------------------------------------------------*/ -#define SIGNBIT 020000000000 - /* most significant bit of 32 bit word */ -#define IBASE 0100000 - /* 2^15 (ie 8^5) so digit is a positive short */ +#define SIGNBIT 020000000000 /* most significant bit of 32 bit word */ +#define IBASE 0100000 /* 2^15 (ie 8^5) so digit is a positive short */ #define MAXDIGIT 077777 #define DIGITWIDTH 15 + #define digit0(x) (hd[x]&MAXDIGIT) #define digit(x) hd[x] #define rest(x) tl[x] @@ -22,10 +21,10 @@ #define bigzero(x) (!digit(x)&&!rest(x)) #define getsmallint(x) (hd[x]&SIGNBIT?-digit0(x):digit(x)) #define stosmallint(x) make(INT,(x)<0?SIGNBIT|(-(x)):(x),0) + long long get_int(word); word sto_int(long long); double bigtodbl(word); -long double bigtoldbl(word); /* not currently used */ double biglog(word); double biglog10(word); int bigcmp(word,word); @@ -46,17 +45,8 @@ word bigxscan(char *,char *); word dbltobig(double); int isnat(word); word strtobig(word,int); -#define force_dbl(x) (tag[x]==INT?bigtodbl(x):get_dbl(x)) -#define PTEN 10000 - /* largest power of ten < IBASE (used by bigscan) */ -#define PSIXTEEN 4096 - /* largest power of sixteen <= IBASE (used by bigtostr) */ -#define PEIGHT 0100000 - /* (=32768) largest power of eight <= IBASE (used by bigtostr) */ -#define TENW 4 - /* number of factors of 10 in PTEN */ -#define OCTW 5 - /* number of factors of 8 in IBASE */ + +#define force_dbl(x) ((tag[(x)] == INT) ? bigtodbl((x)) : get_dbl((x))) /* END OF DEFINITIONS FOR INTEGER PACKAGE */ |