Skip to content
Permalink
Browse files

Parse scientific notation numbers using div_In

  • Loading branch information...
pmurias authored and zoffixznet committed Mar 19, 2018
1 parent 63617a8 commit 8422d7b4e23678b5a6ccbc42550e92ce5140e76b
Showing with 12 additions and 4 deletions.
  1. +12 −4 src/Perl6/Actions.nqp
@@ -7892,6 +7892,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;

@@ -7914,12 +7915,19 @@ class Perl6::Actions is HLL::Actions does STDActions {
}

if $<escale> { # 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($<escale>.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($<escale>.ast, $Int), $Num, $Int);
$n := nqp::islt_I($<escale>.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($/);

0 comments on commit 8422d7b

Please sign in to comment.
You can’t perform that action at this time.