Hi,
With python3 installed, I'm able to access (from within a perl script) the values that python3 prints out for a particular double ($d) by shelling out as follows:
use strict;
use warnings;
my $d = 2 ** -1074;
my $py = `python3 -c \"print($d)\"`;
print "$py\n";
# prints 5e-324
Now, that's about the full extent of my python3 skills, and it works well enough for my purposes even though shelling out is quite an expensive operation.
But that only works as I intend if $d is a 'double' - ie when $Config{nvtype} is 'double'.
How do I get access to the output of 'long double' and '__float128' values in python3 - ie when perl's nvtype (and hence $d) is 'long double' or '__float128' ?
I couldn't quickly google up an answer to that question ... so I'm asking here in the event that some kind soul might be able to help me out.
<pathetic cringe>
By way of explanation:
Python3 has a rather nice approach to the (base 10) presentation of floating point values. It will provide as few digits as are needed.
The script above is a good example. Perl will tell you:
C:\>perl -le "print 2 ** -1074;"
4.94065645841247e-324
And python3 will claim:
$ python3 -c "print(2 ** -1074)"
5e-324
The 2 values appear to be different ... but they're not, and perl will even tell you so:
C:\>perl -le "print 'ok' if 5e-324 == 4.94065645841247e-324;"
ok
It therefore begs the question "Why go to the (obfuscating ?) trouble of providing all of those extra digits when they don't provide greater accuracy ?".
It's a good question - though there are answers and the question is
not necessarily a rhetorical one.
Anyway, I've written a perl implementation (using Math::MPFR, Math::GMPz, Math::GMPq) of the python3 approach to base 10 output of floating point values, and I need to test it.
The internal consistency checks are looking fine, but I also want to check against some trustworthy external source - largely to check that I've got the standardised output working as per the .... ummm .... standard.
That's why I'm referencing python3, and it's checking out well for double precision floating point values.
Now it's just a matter of checking the 'long double' and '__float128' precision values.
Hence my request for assistance.
</pathetic cringe>
Is there a better "trustworthy external source" that I should be using ?
Is there a C library available that already implements
this algorithm ? (Note that the PDF file to which I've linked provides only pages 112-126 of the book. I've implemented the algorithm on page 120.)
Incidentally,
Zefram had indicated an interest in implementing this particular algorithm into the perl source, but I've seen no postings from him anywhere since his perl5 grant ran out last year.
Cheers,
Rob