Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

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

28495 views
License: GPL3
ubuntu2004
1
#include "pari.h"
2
3
GEN gen_0, gen_1, gen_m1, gen_2, gen_m2;
4
THREAD pari_sp avma;
5
THREAD size_t memused = 0;
6
ulong DEBUGLEVEL,DEBUGMEM = 0;
7
const double LOG10_2 = 0.;
8
const long lontyp[] = {0};
9
THREAD VOLATILE int PARI_SIGINT_block, PARI_SIGINT_pending;
10
struct pari_mainstack * pari_mainstack;
11
long *varpriority;
12
13
void mt_sigint_block(void) { }
14
void mt_sigint_unblock(void) { }
15
void new_chunk_resize(size_t x) {(void)x;}
16
17
void specinit()
18
{
19
long size = 100000L;
20
pari_mainstack = malloc(sizeof(*pari_mainstack));
21
pari_mainstack->size = size;
22
pari_mainstack->bot = (pari_sp)malloc(size);
23
pari_mainstack->top = avma = pari_mainstack->bot + size;
24
gen_0 = cgeti(2); affui(0, gen_0);
25
gen_1 = utoipos(1);
26
gen_m1= utoineg(1);
27
gen_2 = utoipos(2);
28
gen_m2= utoineg(2);
29
}
30
31
void sorstring(ulong x)
32
{
33
#ifdef LONG_IS_64BIT
34
if (x>>32) printf("%08lx ", x>>32);
35
printf("%08lx ", x & 0xFFFFFFFF);
36
#else
37
printf("%08lx ", x);
38
#endif
39
}
40
41
void _voiri(GEN x)
42
{
43
long i, lx = lgefint(x);
44
GEN y = int_MSW(x);
45
printf("signe: %ld, ",signe(x));
46
for (i=2; i < lx; i++, y = int_precW(y)) sorstring(*y);
47
printf("\n");
48
}
49
void _voirr(GEN x)
50
{
51
long i, lx = lg(x);
52
printf("signe: %ld, expo: %ld, ",signe(x),expo(x));
53
for (i=2; i < lx; i++) sorstring(x[i]);
54
printf("\n");
55
}
56
57
int main()
58
{
59
GEN x,y,r,z, xr,yr;
60
specinit();
61
x = utoipos(187654321UL);
62
y = utoineg(12345678UL);
63
printf("INT: %ld\n", itos(x));
64
printf("conv:"); _voiri(x);
65
printf("+:"); _voiri(addii(x,y));
66
printf("-:"); _voiri(subii(x,y));
67
printf("*:"); _voiri(mulii(x,y));
68
printf("/:"); _voiri(dvmdii(x,y, &z));
69
printf("rem:"); _voiri(z);
70
printf("pow:\n");
71
z = mulii(x,x); _voiri(z);
72
z = mulii(z,z); _voiri(z);
73
z = mulii(z,z); _voiri(z);
74
z = mulii(z,z); _voiri(z);
75
z = mulii(z,z); _voiri(z);
76
printf("invmod:"); invmod(y,z,&r); _voiri(r);
77
xr = itor(x, DEFAULTPREC);
78
yr = itor(y, DEFAULTPREC);
79
printf("\nREAL: %f\n", rtodbl(xr));
80
printf("conv1:"); _voirr(xr);
81
printf("conv2:"); _voirr(dbltor(rtodbl(xr)));
82
printf("+:"); _voirr(addrr(xr,yr));
83
printf("-:"); _voirr(subrr(xr,yr));
84
printf("*:"); _voirr(mulrr(xr,yr));
85
printf("/:"); _voirr(divrr(xr,yr));
86
printf("gcc bug?:"); _voirr(divru(dbltor(3.),2));
87
return 0;
88
}
89
90