There are reasons to worry, most notable with regards to the bitwise operands, &, |, ^, ~ on one hand, << and >> on the other. And % also has a limit on the range for which it works reliable — very system dependent, I've had a perl 5.005 for which modulo calculations with a number > 2**32 always returned zero, but on my newer port, I can go up to 2**52 or 2**53 (I don't recall exactly), the mantissa part of an IEEE double float, of 64 bits.
This meaningfulness does give a clue on how to efficiently test how large the range can be: I'm quite convinced the limit is always closely related to a power of 2 so one could shift a number to the left, until the result differs from the number times 2, in floating point calculation.
my $i = 0;
my $n = my $m = 1;
while($n == $m) {
$n <<= 1;
$m *= 2;
$i++;
}
print "different for $m (2**$i)\n";
I get:
different for 4294967296 (2**32)
What precisely this implies, I leave as an exercise for the reader. :)
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|