# What is BigNum?

Is BigNum something that somehow calculates big numbers that Luau cant? (e.g. 10^40 numbers).
Something like this BigNum ModuleScript.

What’s the official limit that Luau will have trouble calculating? (e.g. 10^23)

`math.huge` is the biggest number possible(although it will be named as `inf`). According to the developer hub, “The maximum numerical value that may be stored is 2^53, or 9,007,199,254,740,992, and the minimum is -9,007,199,254,740,992. It stores up to 15 digits of precision”.

The BigNum module mentioned above could be used to work with numbers outside that limit. There are also libraries like this for other languages like C.

1 Like

How come this number is bigger than 2^53? If it can’t store it, it can’t do calculations with it.

``````
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MoneyLib = require(ReplicatedStorage.MoneyLib)

local function StartOperation()
local num = 15
while true do
num *= 1.15
print(MoneyLib.DealWithPoints(num), "----------", num)
if num >= 10 ^ 60 then
break
end
wait(0.1)
end
end

wait(3)
StartOperation()
-- After a long time...
--[[
17:26:11.866  424OcD ---------- 4.2472861317277e+59  -  Server - Script:9
17:26:11.966  488OcD ---------- 4.8843790514868e+59  -  Server - Script:9
17:26:12.084  561OcD ---------- 5.6170359092098e+59  -  Server - Script:9
17:26:12.199  645OcD ---------- 6.4595912955913e+59  -  Server - Script:9
17:26:12.316  742OcD ---------- 7.42852998993e+59  -  Server - Script:9
17:26:12.433  854OcD ---------- 8.5428094884195e+59  -  Server - Script:9
17:26:12.549  982OcD ---------- 9.8242309116824e+59  -  Server - Script:9
17:26:12.649  1.12NvD ---------- 1.1297865548435e+60  -  Server - Script:9
]]--
``````

Edit: I remember getting to something like 10^270 before it started saying it was inf.

Edit2: I prob should’ve used runservice.

Improved version

``````local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local MoneyLib = require(ReplicatedStorage.MoneyLib)

local function StartOperation()
local num = 15
while true do
num *= 1.15
print(MoneyLib.DealWithPoints(num), "----------", num)
if num >= 10 ^ 500 then
break
end
RunService.Heartbeat:Wait()
end
end

wait(3)
StartOperation()

--[[
After a long time...
17:34:49.099  8.7695317786717e+307 ---------- 8.7695317786717e+307  -  Server - Script:10
17:34:49.113  1.0084961545472e+308 ---------- 1.0084961545472e+308  -  Server - Script:10
17:34:49.131  1.1597705777293e+308 ---------- 1.1597705777293e+308  -  Server - Script:10
17:34:49.149  1.3337361643887e+308 ---------- 1.3337361643887e+308  -  Server - Script:10
17:34:49.164  1.533796589047e+308 ---------- 1.533796589047e+308  -  Server - Script:10
17:34:49.181  1.7638660774041e+308 ---------- 1.7638660774041e+308  -  Server - Script:10
17:34:49.197  inf ---------- inf  -  Server - Script:10
]]

Edit: Uh.. Apparently MoneyLib can only go up to 10 ^ 123``````

The comment in the module explains how it stores big numbers:

``````--    A Big Number is a table with as many numbers as necessary to represent
--       its value in base 'RADIX'. It has a field 'len' containing the num-
--       ber of such numbers and a field 'signal' that may assume the values
--       '+' and '-'.
``````

IntValues have a cap much lower than NumberValues which can go to 1e+308 or 10^308.

Once you reach past that you will get INF.

I personally don’t recommend BigNum, as it heavily lags with more than a few calculations per second, which is needed. You could also write your own module to get numbers above the 1e+308 cap. I’ve already written such a module, and it has a max of 1e+1e+308.

1 Like

I don’t really need to go over 1e300 cap, in fact I only need to go up to 10 ^ 61. I read a post by Kampf that NumberValues started having trouble storing numbers pass 10 ^ 23. I’ll look for the post.

The trouble of storing numbers past 10^23 is a floating point precision error, and it simply means its not as accurate. In the post you mentioned, even though he multiplied by 10, it ended up being something a little wrong.

Once you start hitting that large of numbers, you should have a system to compact it, such as compact notation (1000 to 1k). Those errors won’t even be visible if you do that, and unless you NEED it to be 100% accurate, which normally you don’t, its fine.

1 Like

I thought he meant that numbervalues just stopped working because it broke once hitting 10 ^ 23. So I guess I know now.

Nope, just a little inaccurate is all.

1 Like