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-2018 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
#include "pari.h"
16
#include "paripriv.h"
17
18
GEN
19
galoisnbpol(long a)
20
{
21
GEN n;
22
pariFILE *F;
23
char *s = stack_malloc(strlen(pari_datadir) + 11 + 20 + 1);
24
sprintf(s,"%s/galpol/%ld/nb", pari_datadir, a);
25
F = pari_fopengz(s);
26
if (!F) pari_err_FILE("galpol file",s);
27
n = gp_read_stream(F->file);
28
if (!n || typ(n)!=t_INT) pari_err_FILE("galpol file [incompatible]",s);
29
pari_fclose(F); return n;
30
}
31
32
GEN
33
galoisgetpol(long a, long b, long sig)
34
{
35
pariFILE *F;
36
GEN V;
37
const char *si;
38
char *s;
39
if (a<=0) pari_err_DOMAIN("galoisgetpol", "degree", "<=", gen_0, stoi(a));
40
if (b<0) pari_err_DOMAIN("galoisgetpol", "index", "<", gen_0, stoi(b));
41
if (!b) return galoisnbpol(a);
42
switch(sig)
43
{
44
case 1: si="real"; break;
45
case 2: if (a%2==0) { si="complex"; break; }
46
pari_err_DOMAIN("galoisgetpol", "s", ">", gen_1, stoi(sig));
47
default:
48
pari_err_FLAG("galoisgetpol");
49
return NULL;/*LCOV_EXCL_LINE*/
50
}
51
/* left on stack */
52
s = stack_sprintf("%s/galpol/%ld/%ld/%s", pari_datadir, a,b,si);
53
F = pari_fopengz(s);
54
if (!F)
55
{
56
long n = itos(galoisnbpol(a));
57
if (b > n)
58
pari_err_DOMAIN("galoisgetpol", "group index", ">", stoi(n), stoi(b));
59
else pari_err_FILE("galpol file", s);
60
}
61
V = gp_read_stream(F->file);
62
if (!V || typ(V)!=t_VEC) pari_err_FILE("galpol file", F->name);
63
pari_fclose(F); return V;
64
}
65
66
GEN
67
galoisgetgroup(long a, long b)
68
{
69
pariFILE *F;
70
GEN V;
71
char *s;
72
if (a<=0) pari_err_DOMAIN("galoisgetgroup", "degree", "<=", gen_0, stoi(a));
73
if (b<0) pari_err_DOMAIN("galoisgetgroup", "index", "<", gen_0, stoi(b));
74
if (!b) return galoisnbpol(a);
75
/* left on stack */
76
s = stack_sprintf("%s/galpol/%ld/%ld/group", pari_datadir, a,b);
77
F = pari_fopengz(s);
78
if (!F)
79
{
80
long n = itos(galoisnbpol(a));
81
if (b > n)
82
pari_err_DOMAIN("galoisgetgroup", "group index", ">", stoi(n), stoi(b));
83
else pari_err_FILE("galpol file", s);
84
}
85
V = gp_read_stream(F->file);
86
if (!V || typ(V)!=t_VEC) pari_err_FILE("galpol file", F->name);
87
pari_fclose(F); return V;
88
}
89
90
GEN
91
galoisgetname(long a, long b)
92
{
93
pariFILE *F;
94
GEN V;
95
char *s;
96
if (a<=0) pari_err_DOMAIN("galoisgetname", "degree", "<=", gen_0, stoi(a));
97
if (b<0) pari_err_DOMAIN("galoisgetname", "index", "<", gen_0, stoi(b));
98
/* left on stack */
99
s = stack_sprintf("%s/galpol/%ld/%ld/name", pari_datadir, a,b);
100
F = pari_fopengz(s);
101
if (!F)
102
{
103
long n = itos(galoisnbpol(a));
104
if (b > n)
105
pari_err_DOMAIN("galoisgetname", "group index", ">", stoi(n), stoi(b));
106
else pari_err_FILE("galpol file", s);
107
}
108
V = gp_read_stream(F->file);
109
if (!V || typ(V)!=t_STR) pari_err_FILE("galpol file", F->name);
110
pari_fclose(F); return V;
111
}
112
113