https://github.com/rootmos/lua-bigint
A small arbitrary precision integer Lua library
https://github.com/rootmos/lua-bigint
Last synced: about 1 year ago
JSON representation
A small arbitrary precision integer Lua library
- Host: GitHub
- URL: https://github.com/rootmos/lua-bigint
- Owner: rootmos
- Created: 2025-04-17T20:09:41.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-05-04T20:08:03.000Z (about 1 year ago)
- Last Synced: 2025-05-04T22:55:32.135Z (about 1 year ago)
- Language: Haskell
- Homepage:
- Size: 345 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# lua-bigint
[](https://github.com/rootmos/lua-bigint/actions/workflows/tests.yaml)
A small arbitrary precision integer Lua library,
with an [exhaustive test suite](tests/src) using Haskell's
[QuickCheck](https://hackage.haskell.org/package/QuickCheck)
and [HsLua](https://hackage.haskell.org/package/hslua).
## Example
```lua
local N = require("bignat")
local a = N.fromstring("78840069980359889583804398923873743190317791505792283599345825435746711")
local b = N.fromstring("6952646245343968493900761108507")
local c = N.fromstring("8177365527942")
local d = N.fromstring("364781755081040559817863568837659573725854950265808819869491980")
local f = 7319870
print((a - b + 0)//c + ((d//2)*2)*f)
```
```
2670155025574697618046118568329646385071709964952686972394605618273230
```
## Try it out
Download [bignat.lua](https://github.com/rootmos/lua-bigint/releases/latest/download/bignat.lua)
from the [latest](https://github.com/rootmos/lua-bigint/releases/latest) release
and chuck it into Lua:
```sh
lua -l N=bignat -e 'print(N.build_info)'
```
### Or grab the latest pre-release using [`gh`](https://cli.github.com/manual/gh_release)
```sh
gh release download "$(gh release list --json tagName --jq '.[0].tagName')" --pattern bignat.lua
```
### Or build from the source
```
./mk-dist && ls dist
```
### Or use the development scripts
The [`run`](run) and [`repl`](repl) scripts:
* download and verify the Lua version specified in the [`deps/lua/lua.json`](deps/lua/lua.json) file,
* [builds](deps/lua/build) both 32 and 64 bit versions and select which depending on the `LUA_BITS` environment variable,
* and adds the [`src`](src) directory to Lua's `package.path`.