# Round to the next 100
while (($i % 100) != 0) {
$i++;
}
print "$i\n";
exit;
+-----------------------------------------------------------+
| I'd give my right arm to be ambidextrous. | eric@fooz.com |
+-----------------------------------------------------------+
On Tue, 24 Aug 1999 at 13:44:07 -0700, Eric Desch wrote:
The following code results in an infinite loop (it works with smaller
values of $i, but I don't know the limit for when it works/doesn't work).
This was on SunOS 5.5.1, in case that matters.
my ($i) = 457396837198630;
while (($i % 100) != 0) {
$i++;
}
Perl uses floating point for normal numbers, which suits most uses. It
is prepared to calculate the modulus of one of these for you, but you
have to be aware that at some point it's going to be approximate.
Read a general computer science book on floating point if this confuses
or bothers you.
You can use Math::BigInt if you want to manipulate very large integers
exactly:
use Math::BigInt;
my $i = new Math::BigInt '457396837198630';
... and the rest of your program is the same.
(Older versions of BigInt spit out 'undefined' warnings all over the
place. This has been fixed in the current development version of perl.)
Migrated from rt.perl.org#1270 (status was 'resolved')
Searchable as RT1270$
The text was updated successfully, but these errors were encountered: