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) 2004 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
/******************************************************************/
16
/* */
17
/* PARI header file (common to all versions) */
18
/* */
19
/******************************************************************/
20
#ifdef STMT_START /* perl headers */
21
# undef STMT_START
22
#endif
23
#ifdef STMT_END
24
# undef STMT_END
25
#endif
26
/* STMT_START { statements; } STMT_END;
27
* can be used as a single statement, as in
28
* if (x) STMT_START { ... } STMT_END; else ...
29
* [ avoid "dangling else" problem in macros ] */
30
#define STMT_START do
31
#define STMT_END while (0)
32
/*=====================================================================*/
33
/* pari_CATCH(numer) {
34
* recovery
35
* } pari_TRY {
36
* code
37
* } pari_ENDCATCH
38
* will execute 'code', then 'recovery' if exception 'numer' is thrown
39
* [ any exception if numer == CATCH_ALL ].
40
* pari_RETRY = as pari_TRY, but execute 'recovery', then 'code' again [still catching] */
41
42
extern THREAD jmp_buf *iferr_env;
43
extern const long CATCH_ALL;
44
45
#define pari_CATCH2(var,err) { \
46
jmp_buf *var=iferr_env; \
47
jmp_buf __env; \
48
iferr_env = &__env; \
49
if (setjmp(*iferr_env)) \
50
{ \
51
GEN __iferr_data = pari_err_last(); \
52
iferr_env = var; \
53
if (err!=CATCH_ALL && err_get_num(__iferr_data) != err) \
54
pari_err(0, __iferr_data);
55
56
#define pari_CATCH2_reset(var) (iferr_env = var)
57
#define pari_ENDCATCH2(var) iferr_env = var; } }
58
59
#define pari_CATCH(err) pari_CATCH2(__iferr_old,err)
60
#define pari_RETRY } iferr_env = &__env; {
61
#define pari_TRY } else {
62
#define pari_CATCH_reset() pari_CATCH2_reset(__iferr_old)
63
#define pari_ENDCATCH pari_ENDCATCH2(__iferr_old)
64
65
#define pari_APPLY_same(EXPR)\
66
{ \
67
long i, _l; \
68
GEN _y = cgetg_copy(x, &_l);\
69
for (i=1; i<_l; i++) gel(_y,i) = EXPR;\
70
return _y;\
71
}
72
73
#define pari_APPLY_type(TYPE, EXPR)\
74
{ \
75
long i, _l = lg(x); \
76
GEN _y = cgetg(_l, TYPE);\
77
for (i=1; i<_l; i++) gel(_y,i) = EXPR;\
78
return _y;\
79
}
80
81
#define pari_APPLY_long(EXPR)\
82
{ \
83
long i, _l = lg(x); \
84
GEN _y = cgetg(_l, t_VECSMALL);\
85
for (i=1; i<_l; i++) _y[i] = EXPR;\
86
return _y;\
87
}
88
89
#define pari_APPLY_ulong(EXPR)\
90
{ \
91
long i, _l = lg(x); \
92
GEN _y = cgetg(_l, t_VECSMALL);\
93
for (i=1; i<_l; i++) ((ulong*)_y)[i] = EXPR;\
94
return _y;\
95
}
96
97
extern const double LOG10_2, LOG2_10;
98
#ifndef M_PI
99
# define M_PI 3.14159265358979323846264338327950288
100
#endif
101
#ifndef M_LN2
102
# define M_LN2 0.693147180559945309417232121458176568
103
#endif
104
#ifndef M_E
105
#define M_E 2.7182818284590452354
106
#endif
107
108
/* Common global variables: */
109
extern int new_galois_format, factor_add_primes, factor_proven;
110
extern ulong DEBUGFILES, DEBUGLEVEL, DEBUGMEM, precdl;
111
extern long DEBUGVAR;
112
extern ulong pari_mt_nbthreads;
113
extern THREAD GEN zetazone, bernzone, eulerzone, primetab;
114
extern GEN gen_m1,gen_1,gen_2,gen_m2,ghalf,gen_0,gnil,err_e_STACK;
115
extern THREAD VOLATILE int PARI_SIGINT_block, PARI_SIGINT_pending;
116
117
extern const long lontyp[];
118
extern void (*cb_pari_ask_confirm)(const char *);
119
extern void (*cb_pari_init_histfile)(void);
120
extern int (*cb_pari_whatnow)(PariOUT *out, const char *, int);
121
extern void (*cb_pari_quit)(long);
122
extern void (*cb_pari_sigint)(void);
123
extern int (*cb_pari_handle_exception)(long);
124
extern int (*cb_pari_err_handle)(GEN);
125
extern void (*cb_pari_pre_recover)(long);
126
extern void (*cb_pari_err_recover)(long);
127
extern int (*cb_pari_break_loop)(int);
128
extern int (*cb_pari_is_interactive)(void);
129
extern void (*cb_pari_start_output)(void);
130
extern const char *pari_library_path;
131
extern THREAD long *varpriority;
132
133
/* pari_init_opts */
134
enum {
135
INIT_JMPm = 1,
136
INIT_SIGm = 2,
137
INIT_DFTm = 4,
138
INIT_noPRIMEm = 8,
139
INIT_noIMTm = 16,
140
INIT_noINTGMPm = 32
141
};
142
143
#ifndef HAS_EXP2
144
# undef exp2
145
# define exp2(x) (exp((double)(x)*M_LN2))
146
#endif
147
#ifndef HAS_LOG2
148
# undef log2
149
# define log2(x) (log((double)(x))/M_LN2)
150
#endif
151
152
#define ONLY_REM ((GEN*)0x1L)
153
#define ONLY_DIVIDES ((GEN*)0x2L)
154
155
#define NEXT_PRIME_VIADIFF(p,d) STMT_START { (p) += *(d)++; } STMT_END
156
#define PREC_PRIME_VIADIFF(p,d) STMT_START { (p) -= *--(d); } STMT_END
157
#define NEXT_PRIME_VIADIFF_CHECK(p,d) STMT_START \
158
{ if (!*(d)) pari_err_MAXPRIME(0); NEXT_PRIME_VIADIFF(p,d); } STMT_END
159
160