develooper Front page | perl.perl6.compiler | Postings from April 2018

[perl #128914] [BUG] decimal->float conversion differs for literalsand Str.Num

Thread Previous | Thread Next
From:
Zoffix Znet via RT
Date:
April 13, 2018 10:14
Subject:
[perl #128914] [BUG] decimal->float conversion differs for literalsand Str.Num
Message ID:
rt-4.0.24-14052-1523614449-35.128914-15-0@perl.org
On Fri, 12 Aug 2016 10:24:48 -0700, zefram@fysh.org wrote:
> > "9.998999999999999e0".EVAL - "9.998999999999999e0".Num
> 1.77635683940025e-15
> 
> Observe that the same string yields different Num values when interpreted
> as a Num literal and when coerced.  Where the string is meaningful both
> ways, this is a bug.  Obviously there are some situations where the
> syntax of Perl 6 literals doesn't exactly match what one would expect of
> a Str.Num conversion, but that's not the case here.  Where the syntax
> matches, as it does in this case, or more generally where the same
> digits are presented with the same weights, one would expect the core
> decimal->float conversion to behave the same for both.
> 
> The conversions yielding different values implies that at least one
> of them is individually incorrect.  In this case, the coercion yields
> the correctly-rounded value, and the literal is getting it wrong.
> [perl #128912] is concerned with these conversions being incorrect per se,
> and my test case there used the conversion for literals.  The difference
> between the two forms of decimal->float conversion is not merely a matter
> of literals getting it wrong and coercion getting it right: there are also
> cases where the coercion gets it wrong.  In fact, coercion gets it wrong
> in the [perl #128912] test case: both literal interpretation and coercion
> get "9.999e-5" wrong in the same way.  I have not yet encountered a case
> where literal interpretation gets it right and coercion gets it wrong,
> but nor can I say that there isn't such a case.
> 
> -zefram


Thank you for the report. This is now fixed.

Fix:  https://github.com/rakudo/rakudo/commit/a760ac3cfc6426d9bd2fb00db
      https://github.com/MoarVM/MoarVM/commit/b735866ddee9bd719440e5c82
Test: https://github.com/perl6/roast/commit/4da5909f926e7eb42

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About