Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix parsing of denormal Nums in &val
We can't just raise 10 into a power to a magnitude of a Num,
as denormals' magnitude would not fit into a normal double.

Fix by using an Int instead and then producing the Num with
nqp::div_In op. This aligns the parsing in &val with the
parsing done in the grammar for literal numbers.
  • Loading branch information
zoffixznet committed Mar 25, 2018
1 parent 8422d7b commit 17446fc
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/core/allomorphs.pm6
Expand Up @@ -367,11 +367,20 @@ multi sub val(Str:D $MAYBEVAL, :$val-or-fail) {
if nqp::iseq_i($p, -1);
$pos = $p;

return nqp::p6box_n(nqp::mul_n(
$frac ?? nqp::add_n( $int.Num, nqp::div_n($frac.Num, $base.Num) )
!! $int.Num,
nqp::pow_n(10e0, nqp::atpos($parse, 0).Num)
)) # if we have a zero, handle the sign correctly
my $power := nqp::pow_I(10,
nqp::abs_I(nqp::atpos($parse, 0), Int), Num, Int);

if $frac {
$int := nqp::add_I(
nqp::mul_I($int, $base, Int), $frac, Int);
}
else {
$base := 1;
}
return (nqp::islt_I(nqp::atpos($parse, 0), 0)
?? nqp::div_In($int, nqp::mul_I($base, $power, Int))
!! nqp::div_In(nqp::mul_I($int, $power, Int), $base)
) # if we have a zero, handle the sign correctly
|| nqp::if(nqp::iseq_i($neg, 1), -0e0, 0e0);
}

Expand Down

0 comments on commit 17446fc

Please sign in to comment.