How to determine max range for perl range iterator?

I can exceed perl range iterations, like so, with or without -Mbigint :

 $Β» perl -E 'say $^V; say for (0..shift)' 1e19 v5.16.2 Range iterator outside integer range at -e line 1. 

How can I determine this upper limit by simply not trying until I exceed it?

+4
source share
1 answer

This is IV.

>> works similarly with integers, so you can use

 my $max_iv = -1 >> 1; my $min_iv = -(-1 >> 1) - 1; 

They can also be obtained from size IV.

 my $max_iv = (1 << ($iv_bits-1)) - 1; my $min_iv = -(1 << ($iv_bits-1)); 

Size IV can be obtained using

 use Config qw( %Config ); my $iv_bits = 8 * $Config{ivsize}; 

or

 my $iv_bits = 8 * length pack 'j', 0; 
+7
source

All Articles