H
Haikun
Dear folks,
I'm not sure if this is a bug of the less than "<=" operator, but the
following piece of code looks like a mystery to me.
==== code snippet start =============
#!/usr/bin/perl -w
use strict;
use warnings;
my $start = 0.001;
my $step = 0.001;
for( my $i=$start; $i <= 0.009; $i+=$step){
print "$i\n";
}
==== code snippet end ==============
The output is
0.001
0.002
0.003
0.004
0.005
0.006
0.007
0.008
and 0.009 is missing from the output. If I change "<=" in the for
clause to "le", the output becomes expected.
0.001
0.002
0.003
0.004
0.005
0.006
0.007
0.008
0.009
I know this looks impossible. But if you take a try you'll see it. I'm
using the latest perl 5.8.8 on Windows.
Thanks,
Haikun
I'm not sure if this is a bug of the less than "<=" operator, but the
following piece of code looks like a mystery to me.
==== code snippet start =============
#!/usr/bin/perl -w
use strict;
use warnings;
my $start = 0.001;
my $step = 0.001;
for( my $i=$start; $i <= 0.009; $i+=$step){
print "$i\n";
}
==== code snippet end ==============
The output is
0.001
0.002
0.003
0.004
0.005
0.006
0.007
0.008
and 0.009 is missing from the output. If I change "<=" in the for
clause to "le", the output becomes expected.
0.001
0.002
0.003
0.004
0.005
0.006
0.007
0.008
0.009
I know this looks impossible. But if you take a try you'll see it. I'm
using the latest perl 5.8.8 on Windows.
Thanks,
Haikun