Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
It always brings a smile

It makes me smile, too - and I smile again at the responses that suggest "this is the way it has to be and you just have to live with it".
It's crazy - for years we've been putting up with using base2 approximations of the actual (decimal) values that we're interested in.

Jarrko Hietaniemi has added an option (current blead) that allows perl to be built with an nvtype of __float128.
And this capability will be available in perl-5.22 for any system/compilers that support the (quad) __float128 type - which includes most Linux and windows systems. (It utilises libquadmath.)

Update: Ooops ... libquadmath is available for windows (and the potential exists), but setting nvtype to __float128 is currently done via the configure script, which therefore excludes Windows (as Windows don't run no configure script).

Further, Jarrko did consider enabling perl to be built with NV type of _Decimal64 or _Decimal128. He didn't think about it for very long before deciding it was a crazy idea ... but he did at least ask himself the question.
I don't know his reasons for deeming it crazy, but my reason for deeming it crazy is that gcc's implementation of decimal math is quite lacking in terms of providing the usual math library functions.
AFAIK, all that's provided by gcc are the basic arithmetic functions (add, subtract, multiply, divide). Therefore if this type were to be the NV, then perl would have to provide sqrt, pow, log, exp, and trig functions for it.
Furthermore, gcc provides no strtod64 or strtod128 function, and nor does it provide (s)printf formatting of those types ... more work to be done by perl in assigning/printing.

I think the IBM compiler provides all of those things that are missing in gcc - and if gcc ever catches up, then I'd be pushing for perl to have the capability of setting its NV to one of these decimal data types.

Hopefully, gcc's coverage will eventually improve but, wrt fp arithmetic, most of us are currently stuck with using base2 approximations (for anything other than the basic arithmetic operations).

Has anyone done any work in this area specific to Perl?

I have written Math::Decimal64 and Math::Decimal128 which wrap the _Decimal64 and _Decimal128 math operations.
Have a play with them if you're interested.
They match gcc's coverage - ie no sqrt, pow, log, exp, trig functions and, given the absence of strtod64(), strtod128() and sprint formatters, the input/output functions are a bit kludgy.
(And now I've *exceeded* this month's quota of self-promotion.)

Cheers,
Rob

Update: Math::Decimal should probably be mentioned here - though it performs its decimal operations via strings, not via decimal floating point data types.

In reply to Re: Decimal Floating Point (DFP) and does Perl needs DFP? by syphilis
in thread Decimal Floating Point (DFP) and does Perl needs DFP? by flexvault

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-25 15:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found