What is the perl equivalent of MAX_INT?

Zak picture Zak · Feb 28, 2013 · Viewed 10.6k times · Source

I am new to perl and seeking the lowest value in an @array. Is there some constant that represents a very large integer number?

I know I could sort the array and take the beginning, but that seems to be a lot of wasted CPU cycles. What is an elegant solution to my problem in Perl?

Answer

ikegami picture ikegami · Feb 28, 2013

To answer you the question you actually asked (even though it's not really of use to you):

  1. Largest integer value that can be stored as a signed integer.

    say ~0 >> 1;
    
  2. Largest integer value that can be stored as an unsigned integer.

    say ~0;
    
  3. All integer values from 0 to this number can be stored without loss as a floating point number.

    use Config qw( %Config );
    say eval($Config{nv_overflows_integers_at});
    

    Note that some larger integers can be stored without loss in a floating point number, but not the one 1 higher than this.