summaryrefslogtreecommitdiff
path: root/src/lgmp.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/lgmp.lua')
-rw-r--r--src/lgmp.lua48
1 files changed, 25 insertions, 23 deletions
diff --git a/src/lgmp.lua b/src/lgmp.lua
index 98bc6af..38da3ee 100644
--- a/src/lgmp.lua
+++ b/src/lgmp.lua
@@ -20,15 +20,21 @@ local error = error
local match = string.match
local prv
-local aux
+local aux = {}
local randmeta = {}
local zmeta = {}
local fmeta = {}
+aux.randmeta = randmeta
+aux.zmeta = zmeta
+aux.fmeta = fmeta
+
randmeta.__index = randmeta
zmeta.__index = zmeta
fmeta.__index = fmeta
+gmp = {}
+
local function isrand(obj)
return type(obj) == "userdata" and getmetatable(obj) == randmeta
end
@@ -100,7 +106,7 @@ end
local dtoz
local dtof
-function z(value, base)
+function gmp.z(value, base)
if value == nil then
return prv.mpz_init()
elseif type(value) == "number" then
@@ -125,7 +131,7 @@ function z(value, base)
end
end
-function f(value, base)
+function gmp.f(value, base)
if value == nil then
return prv.mpf_init()
elseif type(value) == "number" then
@@ -303,7 +309,7 @@ function zmeta:bin(a, res)
return prv.mpz_bin_ui(self, a, res)
end
-function bin(a1, a2, res)
+function gmp.bin(a1, a2, res)
checku(a2)
checkzopt(res)
local t = ntype(a1)
@@ -521,7 +527,7 @@ function zmeta:divisible_2exp(a)
return prv.mpz_divisible_2exp_p(self, a) ~= 0
end
-function fac(a, res)
+function gmp.fac(a, res)
checku(a)
checkzopt(res)
return prv.mpz_fac_ui(a, res)
@@ -609,13 +615,13 @@ function zmeta:fdiv(a)
end
end
-function fib(a, res)
+function gmp.fib(a, res)
checku(a)
checkzopt(res)
return prv.mpz_fib_ui(a, res)
end
-function fib2(a, r1, r2)
+function gmp.fib2(a, r1, r2)
checku(a)
checkzopt(r1)
checkzopt(r2)
@@ -782,13 +788,13 @@ function zmeta:lcm(a, res)
end
end
-function lucnum(a, res)
+function gmp.lucnum(a, res)
checku(a)
checkzopt(res)
return prv.mpz_lucnum_ui(a, res)
end
-function lucnum2(a, r1, r2)
+function gmp.lucnum2(a, r1, r2)
checku(a)
checkzopt(r1)
checkzopt(r2)
@@ -1134,7 +1140,7 @@ function zmeta:tstbit(a)
return prv.mpz_tstbit(self, a)
end
-function pow(a1, a2, res)
+function gmp.pow(a1, a2, res)
checku(a2)
checkzopt(res)
local t = ntype(a1)
@@ -1343,7 +1349,7 @@ function fmeta:reldiff(a, res)
return prv.mpf_reldiff(self, a, res)
end
-function set_default_prec(a)
+function gmp.set_default_prec(a)
checku(a)
prv.mpf_set_default_prec(a)
end
@@ -1389,7 +1395,7 @@ function fmeta:sqrt(res)
return prv.mpf_sqrt(self, res)
end
-function sqrt(a, res)
+function gmp.sqrt(a, res)
checku(a)
checkfopt(res)
return prv.mpf_sqrt_ui(a, res)
@@ -1532,7 +1538,7 @@ function fmeta:__gc()
return prv.mpf_clear(self)
end
-function rand(a)
+function gmp.rand(a)
if a == nil then
return prv.gmp_randinit_default()
else
@@ -1622,21 +1628,17 @@ function fmeta:format(fmt, p)
return prv.mpf_asprintf("%" .. fw .. prec .. "F" .. conv, self, p)
end
-function lgmp_lua_init(l_prv, l_aux)
+function lgmp_lua_init(l_prv)
prv = l_prv
- aux = l_aux
-
- aux.randmeta = randmeta
- aux.zmeta = zmeta
- aux.fmeta = fmeta
-
- lgmpversion = prv.version
dtoz = prv.mpz_init_set_d
dtof = prv.mpf_init_set_d
- get_default_prec = prv.mpf_get_default_prec
+ gmp.get_default_prec = prv.mpf_get_default_prec
+ gmp.version = prv.version
+
+ lgmp_lua_init = nil
- lgmp_init = nil
+ return aux
end