{"id":18020929,"url":"https://github.com/edubart/lua-bint","last_synced_at":"2025-05-07T04:04:54.354Z","repository":{"id":41159783,"uuid":"277215869","full_name":"edubart/lua-bint","owner":"edubart","description":"Arbitrary precision integer arithmetic library in pure Lua","archived":false,"fork":false,"pushed_at":"2024-12-23T20:23:07.000Z","size":182,"stargazers_count":64,"open_issues_count":1,"forks_count":7,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-05-07T04:04:48.740Z","etag":null,"topics":["arbitrary-precision","arbitrary-precision-integers","big","bigint","biginteger","bignum","bignumber","bint","integer","lua"],"latest_commit_sha":null,"homepage":"https://edubart.github.io/lua-bint/","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/edubart.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-05T02:12:27.000Z","updated_at":"2025-04-12T01:19:18.000Z","dependencies_parsed_at":"2024-10-30T06:38:46.395Z","dependency_job_id":null,"html_url":"https://github.com/edubart/lua-bint","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edubart%2Flua-bint","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edubart%2Flua-bint/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edubart%2Flua-bint/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edubart%2Flua-bint/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/edubart","download_url":"https://codeload.github.com/edubart/lua-bint/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252810271,"owners_count":21807760,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arbitrary-precision","arbitrary-precision-integers","big","bigint","biginteger","bignum","bignumber","bint","integer","lua"],"created_at":"2024-10-30T06:08:17.759Z","updated_at":"2025-05-07T04:04:54.330Z","avatar_url":"https://github.com/edubart.png","language":"Lua","readme":"# Lua Bint\n\nSmall portable arbitrary-precision integer arithmetic library in pure Lua for\ncomputing with large integers.\n\nDifferent from most arbitrary-precision integer libraries in pure Lua out there this one\nuses an array of lua integers as underlying data-type in its implementation instead of\nusing strings or large tables, this make it efficient for working with fixed width integers\nand to make bitwise operations.\n\nBint stands for Big Integer.\n\nThe library implementation was highly inspired by\n[tiny-bignum-c](https://github.com/kokke/tiny-bignum-c).\n\nThis library was created to be used in the\n[Nelua programming language](https://github.com/edubart/nelua-lang) compiler.\nIt is successfully used there to handle compile time operations on signed and unsigned integers.\n\n## Design goals\n\nThe main design goal of this library is to be small, correct, self contained and use few\nresources while retaining acceptable performance and feature completeness.\n\nThe library is designed to follow recent Lua integer semantics, this means that\ninteger overflow warps around,\nsigned integers are implemented using two-complement arithmetic rules,\ninteger division operations rounds towards minus infinity,\nany mixed operations with float numbers promotes the value to a float,\nand the usual division/power operation always promotes to floats.\n\nThe library is designed to be possible to work with only unsigned integer arithmetic\nwhen using the proper methods.\n\nAll the lua arithmetic operators (+, -, *, //, /, %) and bitwise operators (\u0026, |, ~, \u003c\u003c, \u003e\u003e)\nare implemented as metamethods.\n\nThe integer size must be fixed in advance and the library is designed to be more efficient when\nworking with integers of sizes between 64-4096 bits. If you need to work with really huge numbers\nwithout size restrictions then use another library. This choice has been made to have more efficiency\nin that specific size range.\n\n## Features\n\n* Small, simple and self contained.\n* Efficient (for a pure Lua integer library).\n* Works with fixed width integers.\n* Follows Lua 5.3+ integer arithmetic semantics by default.\n* All integer overflows wraps around.\n* Can work with large integer widths with reasonable speed (such as 1024bit integers).\n* Implements all lua arithmetic metamethods.\n* Provide methods to work with unsigned arithmetic only.\n* Supports signed integers by default using two-complement arithmetic rules on unsigned operations.\n* Allow to mix any operation with lua numbers, promoting to lua floats where needed.\n* Can perform bitwise operations.\n\n## Documentation\n\nThe full API reference and documentation can be viewed in the\n[documentation website](https://edubart.github.io/lua-bint/).\n\n## Install\n\nYou can use luarocks to install quickly:\n\n```bash\nluarocks install bint\n```\n\nOr just copy the `bint.lua` file, the library is self contained in this single file with no dependencies.\n\n## Examples\n\n```lua\nlocal bint = require 'bint'(256) -- use 256 bits integers\nlocal x = bint(1)\nx = x \u003c\u003c 128\nprint(x) -- outputs: 340282366920938463463374607431768211456\nassert(tostring(x) == '340282366920938463463374607431768211456')\n```\n\nFor more usage examples check the\n[examples directory](https://github.com/edubart/lua-bint/tree/master/examples).\n\nSome interesting examples there:\n\n* [factorial.lua](https://github.com/edubart/lua-bint/blob/master/examples/factorial.lua) - calculate factorial of 100\n* [fibonacci.lua](https://github.com/edubart/lua-bint/blob/master/examples/fibonacci.lua) - calculate the 1001th number of the Fibonacci sequence\n* [pi.lua](https://github.com/edubart/lua-bint/blob/master/examples/pi.lua) - calculate the first 100 digits of Pi\n* [e.lua](https://github.com/edubart/lua-bint/blob/master/examples/e.lua) - calculate the first 100 digits of Euler's number\n* [rsa.lua](https://github.com/edubart/lua-bint/blob/master/examples/rsa.lua) - simple RSA example for encrypting/decrypting messages\n* [secp256k1.lua](https://github.com/edubart/lua-bint/blob/master/examples/secp256k1.lua) - simple Secp256k1 elliptic curve example for encrypting/decrypting/signing messages\n\n## Tests\n\nTo check if everything is working as expected under your machine run `lua tests.lua` or `make test`.\n\n## Limitations\n\nIt is intended only to be used in Lua 5.3+.\nThe library can theoretically be backported to Lua 5.1/LuaJIT but there is no plan at the moment.\nThe integer size is limited in advance, this is a design choice.\n\n## License\n\nMIT License\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedubart%2Flua-bint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fedubart%2Flua-bint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedubart%2Flua-bint/lists"}