Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

Testing latest pari + WASM + node.js... and it works?! Wow.

28485 views
License: GPL3
ubuntu2004
1
/* Copyright (C) 2000 The PARI group.
2
3
This file is part of the PARI/GP package.
4
5
PARI/GP is free software; you can redistribute it and/or modify it under the
6
terms of the GNU General Public License as published by the Free Software
7
Foundation; either version 2 of the License, or (at your option) any later
8
version. It is distributed in the hope that it will be useful, but WITHOUT
9
ANY WARRANTY WHATSOEVER.
10
11
Check the License for details. You should have received a copy of it, along
12
with the package; see the file 'COPYING'. If not, write to the Free Software
13
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
14
15
/* This file defines the parameters of the GEN type */
16
17
#ifdef _WIN64
18
typedef unsigned long long pari_ulong;
19
#define long long long
20
#define labs llabs
21
#else
22
typedef unsigned long pari_ulong;
23
#endif
24
#define ulong pari_ulong
25
typedef long *GEN;
26
27
#undef ULONG_MAX
28
#undef LONG_MAX
29
30
#ifdef LONG_IS_64BIT
31
# define BITS_IN_LONG 64
32
# define TWOPOTBITS_IN_LONG 6
33
# define LONG_MAX (9223372036854775807L) /* 2^63-1 */
34
# define SMALL_ULONG(p) ((ulong)p <= 3037000493UL)
35
#else
36
# define BITS_IN_LONG 32
37
# define TWOPOTBITS_IN_LONG 5
38
# define LONG_MAX (2147483647L) /* 2^31-1 */
39
# define SMALL_ULONG(p) ((ulong)p <= 46337UL) /* 2p^2 < 2^BITS_IN_LONG */
40
#endif
41
#define ULONG_MAX (~0x0UL)
42
43
#define DEFAULTPREC (2 + (long)(8/sizeof(long)))
44
#define MEDDEFAULTPREC (2 + (long)(16/sizeof(long)))
45
#define BIGDEFAULTPREC (2 + (long)(24/sizeof(long)))
46
#define LOWDEFAULTPREC 3
47
#define EXTRAPRECWORD 1
48
#define EXTRAPREC64 ((long)(8/sizeof(long)))
49
#define HIGHBIT (1UL << (BITS_IN_LONG-1))
50
#define BITS_IN_HALFULONG (BITS_IN_LONG>>1)
51
52
#define LOWMASK ((1UL<<BITS_IN_HALFULONG) - 1)
53
#define HIGHMASK (~LOWMASK)
54
55
#define HIGHWORD(a) ((a) >> BITS_IN_HALFULONG)
56
#define LOWWORD(a) ((a) & LOWMASK)
57
58
/* Order of bits in codewords:
59
* x[0] TYPBITS, CLONEBIT, LGBITS
60
* x[1].real SIGNBITS, EXPOBITS
61
* int SIGNBITS, LGBITS
62
* pol SIGNBITS, VARNBITS
63
* ser SIGNBITS, VARNBITS, VALPBITS
64
* padic VALPBITS, PRECPBITS */
65
#define TYPnumBITS 7
66
#define SIGNnumBITS 2
67
68
#ifdef LONG_IS_64BIT
69
# define VARNnumBITS 16 /* otherwise MAXVARN too large */
70
#else
71
# define VARNnumBITS 14
72
#endif
73
74
/* no user serviceable parts below :-) */
75
#define LGnumBITS (BITS_IN_LONG - 1 - TYPnumBITS)
76
#define VALPnumBITS (BITS_IN_LONG - SIGNnumBITS - VARNnumBITS)
77
#define EXPOnumBITS (BITS_IN_LONG - SIGNnumBITS)
78
#define PRECPSHIFT VALPnumBITS
79
#define VARNSHIFT VALPnumBITS
80
#define TYPSHIFT (BITS_IN_LONG - TYPnumBITS)
81
#define SIGNSHIFT (BITS_IN_LONG - SIGNnumBITS)
82
83
#define EXPOBITS ((1UL<<EXPOnumBITS)-1)
84
#define SIGNBITS (~((1UL<<SIGNSHIFT) - 1))
85
#define TYPBITS (~((1UL<< TYPSHIFT) - 1))
86
#define PRECPBITS (~VALPBITS)
87
#define LGBITS ((1UL<<LGnumBITS)-1)
88
#define VALPBITS ((1UL<<VALPnumBITS)-1)
89
#define VARNBITS (MAXVARN<<VARNSHIFT)
90
#define MAXVARN ((1UL<<VARNnumBITS)-1)
91
#define NO_VARIABLE (-1)
92
#define VARARGBITS HIGHBIT
93
#define ARITYBITS (~VARARGBITS)
94
95
#define HIGHEXPOBIT (1UL<<(EXPOnumBITS-1))
96
#define HIGHVALPBIT (1UL<<(VALPnumBITS-1))
97
#define CLONEBIT (1UL<<LGnumBITS)
98
99
#define evaltyp(x) (((ulong)(x)) << TYPSHIFT)
100
#define evalvarn(x) (((ulong)(x)) << VARNSHIFT)
101
#define evalsigne(x) (((ulong)(x)) << SIGNSHIFT)
102
#define _evalexpo(x) (HIGHEXPOBIT + (x))
103
#define _evalvalp(x) (HIGHVALPBIT + (x))
104
#define _evalprecp(x) (((long)(x)) << PRECPSHIFT)
105
#define evallgefint(x) (x)
106
#define evallgeflist(x) (x)
107
#define _evallg(x) (x)
108
109
#define typ(x) ((long)(((ulong)((x)[0])) >> TYPSHIFT))
110
#define settyp(x,s) (((ulong*)(x))[0]=\
111
(((ulong*)(x))[0]&(~TYPBITS)) | evaltyp(s))
112
113
#define isclone(x) (((ulong*) (x))[0] & CLONEBIT)
114
#define setisclone(x) (((ulong*) (x))[0] |= CLONEBIT)
115
#define unsetisclone(x) (((ulong*) (x))[0] &= (~CLONEBIT))
116
117
#define lg(x) ((long)(((ulong)((x)[0])) & LGBITS))
118
#define setlg(x,s) (((ulong*)(x))[0]=\
119
(((ulong*)(x))[0]&(~LGBITS)) | evallg(s))
120
121
#define signe(x) (((long)((x)[1])) >> SIGNSHIFT)
122
#define setsigne(x,s) (((ulong*)(x))[1]=\
123
(((ulong*)(x))[1]&(~SIGNBITS)) | (ulong)evalsigne(s))
124
125
#define lgefint(x) ((long)(((ulong)((x)[1])) & LGBITS))
126
#define setlgefint(x,s) (((ulong*)(x))[1]=\
127
(((ulong*)(x))[1]&(~LGBITS)) | (ulong)evallgefint(s))
128
129
#define realprec(x) ((long)(((ulong)((x)[0])) & LGBITS))
130
#define setprec(x,s) (((ulong*)(x))[0]=\
131
(((ulong*)(x))[0]&(~LGBITS)) | evallg(s))
132
#define incrprec(x) ((x)++)
133
134
#define expo(x) ((long) ((((ulong)((x)[1])) & EXPOBITS) - HIGHEXPOBIT))
135
#define setexpo(x,s) (((ulong*)(x))[1]=\
136
(((ulong*)(x))[1]&(~EXPOBITS)) | (ulong)evalexpo(s))
137
138
#define valp(x) ((long) ((((ulong)((x)[1])) & VALPBITS) - HIGHVALPBIT))
139
#define setvalp(x,s) (((ulong*)(x))[1]=\
140
(((ulong*)(x))[1]&(~VALPBITS)) | (ulong)evalvalp(s))
141
142
#define precp(x) ((long) (((ulong)((x)[1])) >> PRECPSHIFT))
143
#define setprecp(x,s) (((ulong*)(x))[1]=\
144
(((ulong*)(x))[1]&(~PRECPBITS)) | (ulong)evalprecp(s))
145
146
#define varn(x) ((long)((((ulong)((x)[1]))&VARNBITS) >> VARNSHIFT))
147
#define setvarn(x,s) (((ulong*)(x))[1]=\
148
(((ulong*)(x))[1]&(~VARNBITS)) | (ulong)evalvarn(s))
149
150
/* t_LIST */
151
152
#define list_typ(x) ((long)(((ulong)((x)[1])) >> TYPSHIFT))
153
#define list_nmax(x) ((long)(((ulong)((x)[1])) & LGBITS))
154
#define list_data(x) ((GEN*)x)[2]
155
enum {
156
t_LIST_RAW = 0,
157
t_LIST_MAP = 1
158
};
159
160
/* DO NOT REORDER THESE
161
* actual values can be changed. Adapt lontyp in gen2.c */
162
enum {
163
t_INT = 1,
164
t_REAL = 2,
165
t_INTMOD = 3,
166
t_FRAC = 4,
167
t_FFELT = 5,
168
t_COMPLEX= 6,
169
t_PADIC = 7,
170
t_QUAD = 8,
171
t_POLMOD = 9,
172
t_POL = 10,
173
t_SER = 11,
174
t_RFRAC = 13,
175
t_QFB = 15,
176
t_VEC = 17,
177
t_COL = 18,
178
t_MAT = 19,
179
t_LIST = 20,
180
t_STR = 21,
181
t_VECSMALL= 22,
182
t_CLOSURE = 23,
183
t_ERROR = 24,
184
t_INFINITY= 25
185
};
186
187