|There's more than one way to do things|
Re: Decimal Floating Point (DFP) and does Perl needs DFP?by syphilis (Chancellor)
|on Jan 17, 2015 at 01:20 UTC||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.)
Update: Math::Decimal should probably be mentioned here - though it performs its decimal operations via strings, not via decimal floating point data types.