Integer overflow: Difference between revisions

Content added Content deleted
m (→‎{{header|Phix}}: added try/catch note)
(→‎{{header|Lua}}: added Lua solution)
Line 1,733: Line 1,733:
put (-2147483647-1) / -1
put (-2147483647-1) / -1
--> crashes Director (jeez!)</lang>
--> crashes Director (jeez!)</lang>

=={{header|Lua}}==
Lua 5.3+ supports integer and floating sub-types of its generic number type. The ''standard'' implementation is 64-bit signed, under/overflow is not recognized.
<lang Lua>assert(math.type~=nil, "Lua 5.3+ required for this test.")
minint, maxint = math.mininteger, math.maxinteger
print("min, max int64 = " .. minint .. ", " .. maxint)
print("min-1 underflow = " .. (minint-1) .. " equals max? " .. tostring(minint-1==maxint))
print("max+1 overflow = " .. (maxint+1) .. " equals min? " .. tostring(maxint+1==minint))</lang>
{{out}}
<pre>min, max int64 = -9223372036854775808, 9223372036854775807
min-1 underflow = 9223372036854775807 equals max? true
max+1 overflow = -9223372036854775808 equals min? true</pre>


=={{header|M2000 Interpreter}}==
=={{header|M2000 Interpreter}}==