Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: While loop with addition goes weird

by jimpudar (Pilgrim)
on Apr 08, 2018 at 16:57 UTC ( [id://1212544]=note: print w/replies, xml ) Need Help??


in reply to While loop with addition goes weird

Hello chiel,

You should definitely read the pages LanX linked to. The second especially is required reading for anyone who wants to write a computer program.

However, I did want to point out you can use the bignum pragma to get Perl 5 to do what you want:

$ perl -e ' use warnings; use bignum; my $size = 0.01; my $step_size = 0.01; while($size < 5){ $size = $size + $step_size; print $size."\n"; } print "FINAL: ".$size."\n";' ... 4.94 4.95 4.96 4.97 4.98 4.99 5 FINAL: 5

Best,

Jim

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1212544]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-25 14:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found