in reply to Re^2: Decimal Floating Point (DFP) and does Perl needs DFP?
in thread Decimal Floating Point (DFP) and does Perl needs DFP?

They example you used cheats by using a number that's rational in decimal but irrational in binary. If they had picked a number that's irrational in both (e.g. 1000001/999999 instead of 1000001/1000000), both the BFP and the DFP calculations would suffer from the same problem.

DFP helps in some cases, but it might not be the best solution.

  • Comment on Re^3: Decimal Floating Point (DFP) and does Perl needs DFP?

Replies are listed 'Best First'.
Re^4: Decimal Floating Point (DFP) and does Perl needs DFP?
by flexvault (Monsignor) on Jan 24, 2015 at 12:19 UTC

    Hello ikegami,

    Unfortunately, this thread became an accuracy problem/solution discussion.

    My original intent was to discuss the Perl beginner's question of

      " Why isn't Perl as accurate as my calculator? "
    Any experienced programmer, engineer, scientist, etc. understands the problems associated with base n arithmetic. The problem for the new user of any programming language ( Perl preferred ) is '...why does Perl give me 1.999999999999999, when my simple calculator gives me the *correct* answer of 2." They really don't care that it's technically correct, because they want the calculator answer.

    I contributed to this re-direction by showing that I could get the DFP to work on a Linux box with the software shown in the wiki article. I think the writer of the article wanted to show that the integer part of the result was inaccurate (most articles on binary floating point imply the inaccuracy is only after the decimal point). So then the accuracy became the new issue!


    This topic is more about the future of Perl, then about the accuracy of Perl. Just like the calculator designer(s) realized that rounding was an important element if they wanted to sell calculators, I think Perl needs to do a *better* job meeting the expectations of new users.

    Let me be the example:

    I was a system programmer for 15 years and then later an application programmer for many more years before ever using Perl. My stumbling block in the beginning was 'use strict;'. Today all my scripts have that statement. But in the beginning, I would get cryptic warnings, and when I commented out 'use strict;', the script ran and gave the correct answer. But I had to get a lot more experience with Perl before I understood the warning messages. Now I fix the warning and have a better script!


    My original intent was to discuss Decimal Floating Point(DFP) as a way to give calculator like answers for most beginners. When more experienced they could use the speed of binary floating point, but would need to do the rounding themselves.

    I hope I clarified my intended topic.

    Regards...Ed

    "Well done is better than well said." - Benjamin Franklin