1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
/* DEFINITIONS FOR MIRANDA INTEGER PACKAGE (variable length) */
/**************************************************************************
* Copyright (C) Research Software Limited 1985-90. All rights reserved. *
* The Miranda system is distributed as free software under the terms in *
* the file "COPYING" which is included in the distribution. *
* *
* 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 MAXDIGIT 077777
#define digit0(x) (hd[x]&MAXDIGIT)
#define digit(x) hd[x]
#define rest(x) tl[x]
#define big_is_positive(x) (!(hd[x]&SIGNBIT))
#define big_is_negative(x) (hd[x]&SIGNBIT)
#define big_is_zero(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)
/* initialization */
void bigsetup(void);
/* convert between big int and long long */
word big_fromll(long long);
long long big_toll(word);
/* convert between big int and double */
word big_fromd(double);
double big_tod(word);
/* unary negation */
word big_negate(word);
/* compare two big ints */
int big_compare(word, word);
/* basic arithmetic */
word big_add(word, word);
word big_subtract(word, word);
word big_multiply(word, word);
word big_divide(word, word);
word big_remainder(word, word);
/* logarithms and exponentiation */
double big_log(word);
double big_log10(word);
word big_pow(word, word);
/* TODO: combine to make big_tostr(word big, int base) */
word bigtostr(word);
word bigtostr8(word);
word bigtostrx(word);
/* TODO: rename big_fromstr() */
word strtobig(word, int);
/* TODO: combine to make big_scan(char *, ?char*?, int base) */
word bigscan(char *);
word bigoscan(char *, char *);
word bigxscan(char *, char *);
/* TODO: better name and documentation */
int isnat(word);
#define force_dbl(x) ((tag[(x)] == INT) ? big_tod((x)) : get_dbl((x)))
/* END OF DEFINITIONS FOR INTEGER PACKAGE */
|