From 945fdd6ee90f5cf7259b015575d8f476d9e377e6 Mon Sep 17 00:00:00 2001 From: pmurias Date: Mon, 19 Mar 2018 17:05:30 +0100 Subject: [PATCH] Parse scientific notation numbers using div_In --- src/Perl6/Actions.nqp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Perl6/Actions.nqp b/src/Perl6/Actions.nqp index 9fff36f5e62..222bd055a07 100644 --- a/src/Perl6/Actions.nqp +++ b/src/Perl6/Actions.nqp @@ -7714,6 +7714,7 @@ class Perl6::Actions is HLL::Actions does STDActions { method dec_number($/) { my $Int := $*W.find_symbol(['Int']); + my $Num := $*W.find_symbol(['Num']); my $parti; my $partf; @@ -7736,12 +7737,19 @@ class Perl6::Actions is HLL::Actions does STDActions { } if $ { # wants a Num - $parti := nqp::div_In($parti, $partf); - if $parti != 0.0 { - $parti := nqp::mul_n($parti, nqp::pow_n(10, nqp::tonum_I($.ast))); + my num $n; + + if nqp::iseq_I($parti, nqp::box_i(0, $Int)) { + $n := 0; + } else { + my $power := nqp::pow_I(nqp::box_i(10, $Int), nqp::abs_I($.ast, $Int), $Num, $Int); + $n := nqp::islt_I($.ast, nqp::box_i(0, $Int)) + ?? nqp::div_In($parti, nqp::mul_I($partf, $power, $Int)) + !! nqp::div_In(nqp::mul_I($parti, $power, $Int), $partf); } - make $*W.add_numeric_constant($/, 'Num', $parti); + make $*W.add_numeric_constant($/, 'Num', $n); + } else { # wants a Rat my $ast := $*W.add_constant('Rat', 'type_new', $parti, $partf, :nocache(1)); $ast.node($/);