Skip to content

Commit

Permalink
Merge pull request #4669 from MasterDuke17/change_radix_to_just_retur…
Browse files Browse the repository at this point in the history
…n_number_of_chars_converted
  • Loading branch information
MasterDuke17 committed Jan 3, 2022
2 parents 522e49a + 4a3753f commit d94e882
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
12 changes: 8 additions & 4 deletions src/Perl6/Actions.nqp
Expand Up @@ -8347,6 +8347,7 @@ class Perl6::Actions is HLL::Actions does STDActions {
make $*W.add_numeric_constant: $/, 'Num', nqp::numify($/);
} else { # wants a Rat
my $Int := $*W.find_single_symbol('Int');
my $Num := $*W.find_single_symbol('Num');
my $parti;
my $partf;

Expand All @@ -8360,10 +8361,11 @@ class Perl6::Actions is HLL::Actions does STDActions {
if nqp::chars($<frac>) {
$partf := nqp::radix_I(10, $<frac>.Str, 0, 4, $Int);

$parti := nqp::mul_I($parti, $partf[1], $Int);
my $base := nqp::pow_I(nqp::box_i(10, $Int), $partf[1], $Num, $Int);
$parti := nqp::mul_I($parti, $base, $Int);
$parti := nqp::add_I($parti, $partf[0], $Int);

$partf := $partf[1];
$partf := $base;
} else {
$partf := nqp::box_i(1, $Int);
}
Expand All @@ -8386,6 +8388,7 @@ class Perl6::Actions is HLL::Actions does STDActions {
$*W.add_numeric_constant($/, 'Int', $radix), $<circumfix>.ast);
} else { # the "string literal" case
my $Int := $*W.find_single_symbol('Int');
my $Num := $*W.find_single_symbol('Num');

$*W.throw($/, 'X::Syntax::Number::RadixOutOfRange', :$radix) unless (2 <= $radix) && ($radix <= 36);

Expand Down Expand Up @@ -8429,9 +8432,10 @@ class Perl6::Actions is HLL::Actions does STDActions {
);
}

$ipart := nqp::mul_I($ipart[0], $fpart[1], $Int);
my $base := nqp::pow_I(nqp::box_i($radix, $Int), $fpart[1], $Num, $Int);
$ipart := nqp::mul_I($ipart[0], $base, $Int);
$ipart := nqp::add_I($ipart, $fpart[0], $Int);
$fpart := $fpart[1];
$fpart := $base;

my $scientific := nqp::pow_n($bpart, $epart);
$ipart := nqp::mul_I($ipart, nqp::fromnum_I($scientific, $Int), $Int);
Expand Down
7 changes: 4 additions & 3 deletions src/core.c/Str.pm6
Expand Up @@ -2098,20 +2098,21 @@ my class Str does Stringy { # declared in BOOTSTRAP
# Helper path for parsing rats
method !parse-rat(int $radix, Int:D $whole, int $offset --> Numeric:D) {
my $fract := nqp::radix_I($radix,self,$offset,0,Int);
my $base := nqp::pow_I(nqp::box_i($radix,Int),nqp::atpos($fract,1),Num,Int);
nqp::atpos($fract,2) == nqp::chars(self) # fraction parsed entirely?
?? DIVIDE_NUMBERS(
nqp::islt_I($whole,0)
?? nqp::sub_I(
nqp::mul_I($whole,nqp::atpos($fract,1),Int),
nqp::mul_I($whole,$base,Int),
nqp::atpos($fract,0),
Int
)
!! nqp::add_I(
nqp::mul_I($whole,nqp::atpos($fract,1),Int),
nqp::mul_I($whole,$base,Int),
nqp::atpos($fract,0),
Int
),
nqp::atpos($fract,1),
$base,
Rat,
Rat
)
Expand Down
2 changes: 1 addition & 1 deletion src/core.c/allomorphs.pm6
Expand Up @@ -369,7 +369,7 @@ multi sub val(Str:D $MAYBEVAL, Bool :$val-or-fail, Bool :$fail-or-nil) {
$pos = $p;

$frac := nqp::atpos($parse, 0);
$base := nqp::atpos($parse, 1);
$base := nqp::pow_I(nqp::box_i($radix, Int), nqp::atpos($parse, 1), Num, Int);
$ch = nqp::islt_i($pos, $eos) && nqp::ord($str, $pos);
}

Expand Down
2 changes: 1 addition & 1 deletion tools/templates/NQP_REVISION
@@ -1 +1 @@
2021.12
2021.12-6-gce013f1c1

0 comments on commit d94e882

Please sign in to comment.