in reply to Re: Re: How to portably determine integer limits?
in thread How to portably determine integer limits?

Ok - I mean the min/max integer value for a scalar $i at the point where $i-- or $i++ will overflow and fail to return the expected value.
Ah, that's yet another question. First of all, Perl numbers don't "overflow" in the sense that adding 1 to a really big positive number gives you are really small negative number.

Say you have:

$i = 0; $i ++ while forever;
What happens is: If your double has more bits than your integer (a very typical situation, specially in older perls, is having 32 bit integers and 64 bit doubles), there's an interesting situation after the change of representation. 64 bit doubles still have something like 53 bits of precision. So, even with 32 integers, you can still store numbers needing 53 bits without losing precision. And I guess something similar will happen if you have 64 bit integers, and 128 bit doubles.

Abigail

Replies are listed 'Best First'.
Re: Re: How to portably determine integer limits?
by Anonymous Monk on Oct 30, 2003 at 13:43 UTC
    Due to rounding it won't happen if you keep adding 1, but if you keep increasing $i, even the floating point number will run out of bits; then $i becomes "not a number".
    If it's IEEE-754 floating point it should become +Inf...

    Ok, not really. At some point the exponent is going to be large enough that you can't represent a +1 difference in the significand, and $i+1 == $i;
    # nvtype='double', nvsize=8; perl -le 'for$ex(0..128){$i=2**$ex;print"$ex $i"and last if$i==$i+1}'