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

Re: While loop with addition goes weird

by Laurent_R (Canon)
on Apr 08, 2018 at 14:30 UTC ( #1212539=note: print w/replies, xml ) Need Help??


in reply to While loop with addition goes weird

Computers are notoriously bad at computing with decimal numbers. That includes most programming languages.

If you want accurate arithmetic, you might want to try using Perl 6:

> my $size = 0.01; 0.01 > my $step_size = 0.01; 0.01 > $size += $step_size while $size < 5; Nil > say "FINAL: $size"; FINAL: 5
;-)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2020-10-22 07:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (225 votes). Check out past polls.

    Notices?