Testing latest pari + WASM + node.js... and it works?! Wow.
License: GPL3
ubuntu2004
/* Copyright (C) 2004 The PARI group.12This file is part of the PARI/GP package.34PARI/GP is free software; you can redistribute it and/or modify it under the5terms of the GNU General Public License as published by the Free Software6Foundation; either version 2 of the License, or (at your option) any later7version. It is distributed in the hope that it will be useful, but WITHOUT8ANY WARRANTY WHATSOEVER.910Check the License for details. You should have received a copy of it, along11with the package; see the file 'COPYING'. If not, write to the Free Software12Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */1314/******************************************************************/15/* */16/* PARI header file (common to all versions) */17/* */18/******************************************************************/19#ifdef STMT_START /* perl headers */20# undef STMT_START21#endif22#ifdef STMT_END23# undef STMT_END24#endif25/* STMT_START { statements; } STMT_END;26* can be used as a single statement, as in27* if (x) STMT_START { ... } STMT_END; else ...28* [ avoid "dangling else" problem in macros ] */29#define STMT_START do30#define STMT_END while (0)31/*=====================================================================*/32/* pari_CATCH(numer) {33* recovery34* } pari_TRY {35* code36* } pari_ENDCATCH37* will execute 'code', then 'recovery' if exception 'numer' is thrown38* [ any exception if numer == CATCH_ALL ].39* pari_RETRY = as pari_TRY, but execute 'recovery', then 'code' again [still catching] */4041extern THREAD jmp_buf *iferr_env;42extern const long CATCH_ALL;4344#define pari_CATCH2(var,err) { \45jmp_buf *var=iferr_env; \46jmp_buf __env; \47iferr_env = &__env; \48if (setjmp(*iferr_env)) \49{ \50GEN __iferr_data = pari_err_last(); \51iferr_env = var; \52if (err!=CATCH_ALL && err_get_num(__iferr_data) != err) \53pari_err(0, __iferr_data);5455#define pari_CATCH2_reset(var) (iferr_env = var)56#define pari_ENDCATCH2(var) iferr_env = var; } }5758#define pari_CATCH(err) pari_CATCH2(__iferr_old,err)59#define pari_RETRY } iferr_env = &__env; {60#define pari_TRY } else {61#define pari_CATCH_reset() pari_CATCH2_reset(__iferr_old)62#define pari_ENDCATCH pari_ENDCATCH2(__iferr_old)6364#define pari_APPLY_same(EXPR)\65{ \66long i, _l; \67GEN _y = cgetg_copy(x, &_l);\68for (i=1; i<_l; i++) gel(_y,i) = EXPR;\69return _y;\70}7172#define pari_APPLY_type(TYPE, EXPR)\73{ \74long i, _l = lg(x); \75GEN _y = cgetg(_l, TYPE);\76for (i=1; i<_l; i++) gel(_y,i) = EXPR;\77return _y;\78}7980#define pari_APPLY_long(EXPR)\81{ \82long i, _l = lg(x); \83GEN _y = cgetg(_l, t_VECSMALL);\84for (i=1; i<_l; i++) _y[i] = EXPR;\85return _y;\86}8788#define pari_APPLY_ulong(EXPR)\89{ \90long i, _l = lg(x); \91GEN _y = cgetg(_l, t_VECSMALL);\92for (i=1; i<_l; i++) ((ulong*)_y)[i] = EXPR;\93return _y;\94}9596extern const double LOG10_2, LOG2_10;97#ifndef M_PI98# define M_PI 3.1415926535897932384626433832795028899#endif100#ifndef M_LN2101# define M_LN2 0.693147180559945309417232121458176568102#endif103#ifndef M_E104#define M_E 2.7182818284590452354105#endif106107/* Common global variables: */108extern int new_galois_format, factor_add_primes, factor_proven;109extern ulong DEBUGFILES, DEBUGLEVEL, DEBUGMEM, precdl;110extern long DEBUGVAR;111extern ulong pari_mt_nbthreads;112extern THREAD GEN zetazone, bernzone, eulerzone, primetab;113extern GEN gen_m1,gen_1,gen_2,gen_m2,ghalf,gen_0,gnil,err_e_STACK;114extern THREAD VOLATILE int PARI_SIGINT_block, PARI_SIGINT_pending;115116extern const long lontyp[];117extern void (*cb_pari_ask_confirm)(const char *);118extern void (*cb_pari_init_histfile)(void);119extern int (*cb_pari_whatnow)(PariOUT *out, const char *, int);120extern void (*cb_pari_quit)(long);121extern void (*cb_pari_sigint)(void);122extern int (*cb_pari_handle_exception)(long);123extern int (*cb_pari_err_handle)(GEN);124extern void (*cb_pari_pre_recover)(long);125extern void (*cb_pari_err_recover)(long);126extern int (*cb_pari_break_loop)(int);127extern int (*cb_pari_is_interactive)(void);128extern void (*cb_pari_start_output)(void);129extern const char *pari_library_path;130extern THREAD long *varpriority;131132/* pari_init_opts */133enum {134INIT_JMPm = 1,135INIT_SIGm = 2,136INIT_DFTm = 4,137INIT_noPRIMEm = 8,138INIT_noIMTm = 16,139INIT_noINTGMPm = 32140};141142#ifndef HAS_EXP2143# undef exp2144# define exp2(x) (exp((double)(x)*M_LN2))145#endif146#ifndef HAS_LOG2147# undef log2148# define log2(x) (log((double)(x))/M_LN2)149#endif150151#define ONLY_REM ((GEN*)0x1L)152#define ONLY_DIVIDES ((GEN*)0x2L)153154#define NEXT_PRIME_VIADIFF(p,d) STMT_START { (p) += *(d)++; } STMT_END155#define PREC_PRIME_VIADIFF(p,d) STMT_START { (p) -= *--(d); } STMT_END156#define NEXT_PRIME_VIADIFF_CHECK(p,d) STMT_START \157{ if (!*(d)) pari_err_MAXPRIME(0); NEXT_PRIME_VIADIFF(p,d); } STMT_END158159160