From: Brandon Allbery
Sent: Friday, October 13, 2017 4:15 AM
To: sisyph...@optusnet.com.au
Cc: Carl Mäsak via RT
Subject: Re: [perl #132268] Floating point anomalies
On Thu, Oct 12, 2017 at 5:31 AM, <sisyph...@optusnet.com.au> wrote:
Perl6's printf() function looks a little suspect - though I might be missing
something here.

As with perl5's say function, doubles are rounded to 14 decimal digits of precision

To correct that assertion, they both of course round to 15 decimal digits of precision.

I question your use of 'accurate'. The low bits are *never* accurate. They're trying to be more 'precise', but the value they have will depend strongly on how exactly the value was calculated, and there are entirely reasonable design decisions that can cause them to differ between implementations.

I don't think there's anything "reasonable" about a printf() implementation that tells me:

$ perl6 -e 'printf "%.16e\n", Num(sqrt(3e0));'
1.7320508075688800e+00

Perl6 knows quite well that a double assigned a value of 1.7320508075688800e+00 is not equivalent to the double returned by Num(sqrt(3e0)) :

$ perl6 -e 'say "not equivalent" if 1.7320508075688800e0 != Num(sqrt(3e0));'
not equivalent

Furthermore, perl6 also knows quite well that a double assigned the value 1.7320508075688772e+00 *is* equivalent to the double returned by Num(sqrt(3e0)):

$ perl6 -e 'say "ok" if 1.7320508075688772e0 == Num(sqrt(3e0));'
ok

It's bad enough that perl5 and perl6 round to 15 decimal digits of precision, but at least perl5's printf will give me 17 decimal digits when I ask it to (and I think perl6 should do the same):

$ perl -e 'printf "%.16e\n", sqrt(3.0);'
1.7320508075688772e+00

As a feature request, it would also be nice to see "%a" formatting implemented as that then provides one with the means to see the exact value of the given double.

Cheers,
Rob

Reply via email to