Probably silly floating comparison question

dams dams at gentoo.org
Tue Aug 8 10:51:05 BST 2006


Le Tue, 8 Aug 2006 10:04:43 +0100 (BST),
london.pm at welikegoats.com a écrit :

> If we compare the output of:
> 
> my $i = 0;
> while($i <= 2) {
>          $i += .1;
>          print"$i\n";
> }
> 

Strangely enough, if you start with 1.7, it works as expected :

% perl -e 'my $i = 1.7; while($i <= 2) { $i += 0.1; print "$i\n"; }'
1.8
1.9
2
2.1



dams



More information about the london.pm mailing list