(Does this really have to go to three lists? What's this got to do with
admin, for example?

[EMAIL PROTECTED] wrote:
> #!d:\perl\bin\perl.exe
> 
> $num = 0;
> $end = 0.9;
> 
> until ( $num == $end) {
>         print ($num = $num + 0.1, "\n");
> }
> 
> I thing, is write correct, but when I run it, the cycle never 
> ending. Why ?

perldoc -q "long decimals"

Floating-point arithmetic is not exact. So 9 * 0.1 is not exactly 0.9, since
neither 0.1 nor 0.9 are representable exactly. (For example, I get
0.10000000000000001000 and 0.90000000000000002000 when I print those numbers
with 20 decimal places, and 0.89999999999999991000 for 0.1 added to itself
nine times.)

> When I use eq instead ==, the data output is correct. Why ?

Because you're comparing them as strings then. When Perl converts the
fraction to a string, it rounds it, and the rounded version is the same
(i.e. '0.9' eq '0.9' but 0.89999999999999991000 != 0.90000000000000002000).

Using == with floating-point numbers is almost always wrong.

Cheers,
Philip
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activeperl

Reply via email to