Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: floating point addition

by RonW (Parson)
on Jan 13, 2015 at 00:15 UTC ( [id://1113016]=note: print w/replies, xml ) Need Help??


in reply to Re^2: floating point addition
in thread floating point addition

But I don't want to add overloading of NVs as that would defeat the purpose.

How would this defeat the purpose?

Replies are listed 'Best First'.
Re^4: floating point addition
by syphilis (Archbishop) on Jan 13, 2015 at 01:52 UTC
    Because allowing use of NV values re-introduces the very rounding anomalies we're (normally) trying to avoid:
    C:\>perl -MMath::Decimal64=":all" -le "$x=Math::Decimal64->new('0.085' +); $y = Math::Decimal64->new(0.085);$z = NVtoD64(0.085);print $x;prin +t $y; print $z;" Outputs: 85e-3 8500000000000001e-17 8500000000000001e-17
    $y and $z are assigned from the actual NV value, whereas $x is assigned the specified decimal value.

    The trouble with allowing overloading of NVs is that it makes it just too easy for people to inadvertently use a value that they didn't really mean to use - though I guess the same criticism could be levelled at new() because *it* currently allows assignment of NVs.
    NVtoD64() ought to be there so that one *can* assign the NV to a Math::Decimal64 object if one wants. It's name pretty much explicitly indicates what it's going to do, thus making it less likely that one will inadvertently assign an unintended value.

    Cheers,
    Rob

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-19 11:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found