Perl isn't C; if you try to compute an integer that's too large, you get a floating-point result instead (unless you use bigint
, which makes integers unbounded). Beyond that, you get inf
.
You can see this with Devel::Peek
, which shows you Perl's internal representation of a value:
$ perl -E 'use Devel::Peek; Dump(1000); Dump(1000**100); Dump(1000**100 + 1)'
SV = IV(0xcdf290) at 0xcdf2a0
REFCNT = 1
FLAGS = (PADTMP,IOK,READONLY,pIOK)
IV = 1000
SV = NV(0xd04f20) at 0xcdf258
REFCNT = 1
FLAGS = (PADTMP,NOK,READONLY,pNOK)
NV = 1e+300
SV = NV(0xd04f18) at 0xcdf228
REFCNT = 1
FLAGS = (PADTMP,NOK,READONLY,pNOK)
NV = 1e+300
IV
indicates an integer value; NV
indicates a floating-point (Number?) value.
You should definitely use a tool suited to your purpose instead of a fuzzy hack; List::Util::min
as mentioned in another answer is excellent. Just thought you might like confirmation on your original question :)