costica_p
costica_p

Reputation: 51

Lua5.3 vs Lua5.1 on the same code

I have this script for factorial calculus in Lua:

N, F = 1, 1
while F < 1e200 do
print(N .. "! is " .. F)
N = N + 1
-- Compute the factorial of the new N based on
-- the factorial of the old N:
F = F * N
end

What's wrong with this code in Lua 5.3? After 19! everything is weird. But the same code works perfect in Lua 5.1.

Upvotes: 1

Views: 1393

Answers (1)

lhf
lhf

Reputation: 72392

Lua 5.3 supports integers, which have wraparound arithmetic.

Try your code with

N, F = 1, 1.0

to get the same behavior as Lua 5.1.

Upvotes: 2

Related Questions