Integer overflow: Difference between revisions

→‎{{header|PARI/GP}}: crashing a t_INT
m (added whitespace, indented the tables, aligned the notes.)
(→‎{{header|PARI/GP}}: crashing a t_INT)
Line 1,780:
 
=={{header|PARI/GP}}==
Although it appears at a glance that GP offers only <code>t_INT</code> (unlimited precision) integers, in fact machineMachine-sized integers can be used inside a <code>Vecsmall</code>:
<lang parigp>Vecsmall([1])
Vecsmall([2^64])</lang>
Line 1,791:
 
Of course PARI can use the same techniques as [[#C|C]].
 
Additionally, you can, in principle, overflow a <code>t_INT</code>. The length, in words, of a <code>t_INT</code> is given in a single word. Hence on 32 bit a <code>t_INT</code> cannot have more than 2^32-1 words, limiting it to the range
:<math>\{-(2^{2^{32}-1}-1), -(2^{2^{32}-1}-2), \ldots, -2, -1, 0, 1, 2, \ldots, 2^{2^{32}-1}-2, 2^{2^{32}-1}-1\}</math>
with 64-bit
:<math>\{-(2^{2^{64}-1}-1), -(2^{2^{64}-1}-2), \ldots, -2, -1, 0, 1, 2, \ldots, 2^{2^{64}-1}-2, 2^{2^{64}-1}-1\}</math>
 
(Note that these bounds are different from an IEEE 754-style floating point because the sign bit is stored externally.) It takes > 18 exabytes to overflow a <code>t_INT</code> on 64-bit (roughly Google's total storage as of 2014), but it's doable in 32-bit. Has anyone tried? I imagine you'd get a memory error or the like.
 
=={{header|Perl}}==