Work with large numbers in Lua

I need to store a large amount in Lua, for example, number 63680997318088143281752740767766707563546963464218564507450892460763521488675430192536461.

If I just assign a variable, I don't get the actual number:

local n = 63680997318088143281752740767766707563546963464218564507450892460763521488675430192536461
print(string.format("%.0f",n)) -- prints 63680997318088143929455344863959288468423333130904105158115881995380577784972357899649024

What would be the possible turnaround for handling large numbers?

+4
source share
1 answer

Lua numbers have limited accuracy, but you are trying to save a number that exceeds what you can save. You will need to use a different mechanism to store and work with these numbers.

: "bignum" " ". google pure-Lua (bignum lua-nums) C- (lmapm). . SO .

+5

Source: https://habr.com/ru/post/1682083/


All Articles