use Config qw( %Config ); use List::Util qw( max ); my $max = max( ~0+1, eval( $Config{ nv_overflows_integers_at } ) ); #### [+/-]1._____..._____ * 2**____ #### __52 bits__ / \ 1.00000...00000 * 2**53 Large power of two + 1.00000...00000 * 2**0 1 -------------------------- 1.00000...00000 * 2**53 + 0.00000...000001 * 2**53 Normalized exponents -------------------------- 1.00000...000001 * 2**53 But we have limited number of bits -------------------------- 1.00000...00000 * 2**53 Original large power of two #### $ perl -MB=svref_2object,SVf_IVisUV,SVf_NOK -e' $i = 0; $sv = svref_2object(\$i); print $sv->FLAGS & SVf_NOK ? "NV\n" # Float : $sv->FLAGS & SVf_IVisUV ? "UV\n" # Unsigned int : "IV\n"; # Signed int ' IV #### $ perl -MConfig -MB=svref_2object,SVf_IVisUV,SVf_NOK -e' $i = hex("7F".("FF"x($Config{ivsize}-2))."FD"); $sv = svref_2object(\$i); for (1..4) { ++$i; printf $sv->FLAGS & SVf_NOK ? "NV %.0f\n" : $sv->FLAGS & SVf_IVisUV ? "UV %u\n" : "IV %d\n", $i; } ' IV 2147483646 IV 2147483647 <-- 2**31 - 1 Largest IV UV 2147483648 UV 2147483649 #### IV 9223372036854775806 IV 9223372036854775807 <-- 2**63 - 1 Largest IV UV 9223372036854775808 UV 9223372036854775809 #### $ perl -V:[in]vsize ivsize='4'; # 32-bit integers nvsize='8'; # 64-bit floats #### $ perl -V:[in]vsize ivsize='8'; # 64-bit integers nvsize='8'; # 64-bit floats #### $ perl -MConfig -MB=svref_2object,SVf_IVisUV,SVf_NOK -e' $i = eval($Config{nv_overflows_integers_at}) - 3; $sv = svref_2object(\$i); for (1..4) { ++$i; printf $sv->FLAGS & SVf_NOK ? "NV %.0f\n" : $sv->FLAGS & SVf_IVisUV ? "UV %u\n" : "IV %d\n", $i; } ' NV 9007199254740990 NV 9007199254740991 Precision required as a float: NV 9007199254740992 <-- 2**53 1 bit NV 9007199254740992 <-- 2**53 + 1 54 bits, but only 53 are available #### $ perl -MConfig -MB=svref_2object,SVf_IVisUV,SVf_NOK -e' $i = hex(("FF"x($Config{ivsize}-1))."FD"); $sv = svref_2object(\$i); for (1..4) { ++$i; printf $sv->FLAGS & SVf_NOK ? "NV %.0f\n" : $sv->FLAGS & SVf_IVisUV ? "UV %u\n" : "IV %d\n", $i; } ' UV 18446744073709551614 UV 18446744073709551615 <-- 2**64 - 1 Largest UV NV 18446744073709551616 <-- 2**64 1 bit of precision required NV 18446744073709551616 <-- 2**64 + 1 65, but only 53 are available