Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Decimal Increment Bug?

by pryrt (Monsignor)
on Mar 16, 2018 at 19:30 UTC ( #1211075=note: print w/replies, xml ) Need Help??


in reply to Decimal Increment Bug?

What Every Computer Scientist Should Know About Floating-Point Arithmetic

In short: repeated addition of ~0.1 is not the same as n instances of exactly 0.1.

Instead, do something like this:

use warnings; use strict; my $delta = 0.1; my $v = 0; my $i = 0; while( $v < 9 ) { $v = $i * $delta; print $v, $/; ++$i; }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (None)
    As of 2022-01-26 04:24 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      In 2022, my preferred method to securely store passwords is:












      Results (69 votes). Check out past polls.

      Notices?