Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re^2: Is this odd behavior a floating point problem?

by wickedjester (Initiate)
on Mar 23, 2012 at 17:10 UTC ( #961264=note: print w/replies, xml ) Need Help??

in reply to Re: Is this odd behavior a floating point problem?
in thread Is this odd behavior a floating point problem?

Yes, I've seen and skimmed this document, but, not to be rude, but I'm not interested in becoming a computer scientist in order to write a script to do basic math. Adding together 0.001 40 times is pretty basic and if my calculator can do it, I not sure I understand why Perl won't.
  • Comment on Re^2: Is this odd behavior a floating point problem?

Replies are listed 'Best First'.
Re^3: Is this odd behavior a floating point problem?
by davido (Archbishop) on Mar 23, 2012 at 18:09 UTC

    It's not a Perl problem, it's the problem of representing a non-terminating series for base 2 using a finite number of binary digits. You are accustomed to seeing it in base ten when you try to represent 1/3rd, yet I hear no complaints that your ten counting fingers are malfunctioning. Your calculator gets it right by rounding to the eight or ten significant digits that you see on its little LCD display. In other words, it really doesn't get it right; it just covers up the ugliness. And, in fact, I see a nearly identical question every day in reference to C, C++, PHP, and myriad other programming languages over on StackOverflow. It's not a problem unique to Perl.

    I understand that the "What every computer scientist should know..." article is a little beyond what someone who just wants to get the job done might want to digest. That's fine, the article goes into painful details. Try this response (shameless plug, I wrote it), which tries to spell it out in less technical terms: Re: shocking imprecision.


Re^3: Is this odd behavior a floating point problem?
by BrowserUk (Pope) on Mar 23, 2012 at 19:13 UTC

    If you don't like the WhatEvery... article -- and I agree that it is written more to impress than inform; and is way over promoted -- then try this. Short, sweet & clear.

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

Re^3: Is this odd behavior a floating point problem?
by Anonymous Monk on Mar 23, 2012 at 19:38 UTC
Re^3: Is this odd behavior a floating point problem?
by ww (Bishop) on Mar 24, 2012 at 00:29 UTC
    If I were doing it with a calculator, I'd surely end up with too many or too few entries of 0.001. I might mess it up building an array. Are you sure you have the right number of elements?

    You can check easily enough:

    say scalar(@arr); # 40 say $#arr; # 39

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://961264]
[MidLifeXis]: Nothing like encouraging the success of a rollout by neutering your current support structure without a reasonable staffed and trained replacement structure.
[MidLifeXis]: Speaking of which, anyone know of Perl positions in the MKE area (or slightly west)?
[Corion]: MidLifeXis: Oh, enjoying the show from the sidelines I see...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (10)
As of 2017-03-23 12:28 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (286 votes). Check out past polls.