Integer overflow: Difference between revisions

Content added Content deleted
(add RPL)
m (→‎{{header|Wren}}: Changed to Wren S/H)
Line 2,885: Line 2,885:


However, within this overall framework, Wren also has an unsigned 32-bit integer sub-system when dealing with bitwise operations. All values are converted internally to such integers before the corresponding C bitwise operation is performed (Wren's VM is written in C) and can therefore overflow without warning. Fortunately, we can easily observe these effects by performing the operations required by the task and then (for example) right shifting them by 0 places.
However, within this overall framework, Wren also has an unsigned 32-bit integer sub-system when dealing with bitwise operations. All values are converted internally to such integers before the corresponding C bitwise operation is performed (Wren's VM is written in C) and can therefore overflow without warning. Fortunately, we can easily observe these effects by performing the operations required by the task and then (for example) right shifting them by 0 places.
<syntaxhighlight lang="ecmascript">var exprs = [-4294967295, 3000000000 + 3000000000, 2147483647 - 4294967295, 65537 * 65537]
<syntaxhighlight lang="wren">var exprs = [-4294967295, 3000000000 + 3000000000, 2147483647 - 4294967295, 65537 * 65537]
System.print("Unsigned 32-bit:")
System.print("Unsigned 32-bit:")
for (expr in exprs) System.print(expr >> 0)</syntaxhighlight>
for (expr in exprs) System.print(expr >> 0)</syntaxhighlight>