I am pleased to release a copy of the bc (bignum) library.
You can download the DLL, source files, and the GPL document from:
http://www.gammon.com.au/files/mushclient/lua5.1_extras/bc.zip
All you really need is bc.dll, which you can place in the same directory as MUSHclient.exe.
Then you can load the DLL and use it along these lines:
This test demonstrates doing factorials. First it uses a straight Lua number, secondly a "bc" number. The results show the Lua number quickly become floating point numbers, whereas the bc number retains full accuracy:
You can download the DLL, source files, and the GPL document from:
http://www.gammon.com.au/files/mushclient/lua5.1_extras/bc.zip
All you really need is bc.dll, which you can place in the same directory as MUSHclient.exe.
Then you can load the DLL and use it along these lines:
-- test bc library
assert (package.loadlib ("bc.dll","luaopen_bc")) ()
------------------------------------------------------------------------------
print(bc.version)
------------------------------------------------------------------------------
print"Factorials"
function factorial(n,f)
for i=2,n do f=f*i end
return f
end
one=bc.number(1)
for i=1,40 do
print(i,factorial(i,1),factorial(i,one))
end
This test demonstrates doing factorials. First it uses a straight Lua number, secondly a "bc" number. The results show the Lua number quickly become floating point numbers, whereas the bc number retains full accuracy:
bc library for Lua 5.1 / Aug 2006 / based on GNU bc-1.06
Factorials
1 1 1
2 2 2
3 6 6
4 24 24
5 120 120
6 720 720
7 5040 5040
8 40320 40320
9 362880 362880
10 3628800 3628800
11 39916800 39916800
12 479001600 479001600
13 6227020800 6227020800
14 87178291200 87178291200
15 1307674368000 1307674368000
16 20922789888000 20922789888000
17 3.55687428096e+014 355687428096000
18 6.402373705728e+015 6402373705728000
19 1.2164510040883e+017 121645100408832000
20 2.4329020081766e+018 2432902008176640000
21 5.1090942171709e+019 51090942171709440000
22 1.1240007277776e+021 1124000727777607680000
23 2.5852016738885e+022 25852016738884976640000
24 6.2044840173324e+023 620448401733239439360000
25 1.5511210043331e+025 15511210043330985984000000
26 4.0329146112661e+026 403291461126605635584000000
27 1.0888869450418e+028 10888869450418352160768000000
28 3.0488834461171e+029 304888344611713860501504000000
29 8.8417619937397e+030 8841761993739701954543616000000
30 2.6525285981219e+032 265252859812191058636308480000000
31 8.2228386541779e+033 8222838654177922817725562880000000
32 2.6313083693369e+035 263130836933693530167218012160000000
33 8.6833176188119e+036 8683317618811886495518194401280000000
34 2.952327990396e+038 295232799039604140847618609643520000000
35 1.0333147966386e+040 10333147966386144929666651337523200000000
36 3.719933267899e+041 371993326789901217467999448150835200000000
37 1.3763753091226e+043 13763753091226345046315979581580902400000000
38 5.230226174666e+044 523022617466601111760007224100074291200000000
39 2.0397882081197e+046 20397882081197443358640281739902897356800000000
40 8.159152832479e+047 815915283247897734345611269596115894272000000000