Skip to content

Commit

Permalink
Merge branch 'master' into post-release
Browse files Browse the repository at this point in the history
  • Loading branch information
zoffixznet committed Jan 17, 2018
2 parents e34595c + a76455f commit c11e211
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 14 deletions.
7 changes: 1 addition & 6 deletions src/QRegex/Cursor.nqp
Expand Up @@ -425,12 +425,7 @@ role NQPMatchRole is export {
$braid := $!braid."!clone"(); # usually called when switching into a slang
}
else {
if nqp::isconcrete(self) && $!braid {
$braid := Braid."!braid_init"(:grammar(self), :actions(self.actions), :package(nqp::getattr($!braid, Braid, '$!package')));
}
else {
$braid := Braid."!braid_init"(:grammar(self));
}
$braid := Braid."!braid_init"(:grammar(self));
}
}
nqp::die("No braid in cursor_init!") unless $braid;
Expand Down
2 changes: 2 additions & 0 deletions src/vm/js/Compiler.nqp
Expand Up @@ -243,6 +243,8 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {


while $info {
return NQPMu if $info.qast && $info.qast.ann('DYN_COMP_WRAPPER');

$reached_closure_template := $reached_closure_template || $info.qast.blocktype ne 'immediate';

if $info.has_own_variable($var.name) {
Expand Down
4 changes: 4 additions & 0 deletions src/vm/js/Operations.nqp
Expand Up @@ -907,6 +907,10 @@ class QAST::OperationsJS {
my str $var_name := $node[0].value;
my $block := $*BLOCK.outer;
while $block {
if ($block.qast && $block.qast.ann('DYN_COMP_WRAPPER')) {
$block := NQPMu;
last;
}
last if $block.has_own_variable($var_name);
$block := $block.outer;
}
Expand Down
20 changes: 15 additions & 5 deletions src/vm/js/nqp-runtime/bignum.js
Expand Up @@ -139,18 +139,28 @@ op.expmod_I = function(a, b, c, type) {
return makeBI(type, getBI(a).powm(getBI(b), getBI(c)));
};


/* TODO - optimize by using a smaller bignum when so much isn't needed */
const digits = 325;
const digitsBignum = bignum(10).pow(digits);

op.div_In = function(a, b) {
const digits = 1e+20;
const divisor = getBI(b);
if (divisor.eq(0)) {
return getBI(a).toNumber() / 0;
}

const big = getBI(a).mul(bignum(digits)).div(divisor).toString();
if (big.length <= 20) {
return parseFloat('0.' + '0'.repeat(20 - big.length) + big);
let sign = 1;
let big = getBI(a).mul(digitsBignum).div(divisor).toString();
if (big.substr(0, 1) == '-') {
big = big.substr(1);
sign = -1;
}

if (big.length <= digits) {
return sign * parseFloat('0.' + '0'.repeat(digits - big.length) + big);
} else {
return parseFloat(big.substr(0, big.length - 20) + '.' + big.substr(big.length - 20));
return sign * parseFloat(big.substr(0, big.length - digits) + '.' + big.substr(big.length - digits));
}
};

Expand Down
12 changes: 10 additions & 2 deletions t/nqp/060-bigint.t
@@ -1,7 +1,7 @@
#! nqp
use nqpmo;

plan(130);
plan(134);

my $knowhow := nqp::knowhow();
my $bi_type := $knowhow.new_type(:name('TestBigInt'), :repr('P6bigint'));
Expand Down Expand Up @@ -211,11 +211,19 @@ ok(str(nqp::expmod_I(
$bi_type,
)) eq '1527229998585248450016808958343740453059', 'nqp::expmod_I');

ok(nqp::div_In(box(1234500), box(100)) == 12345, 'div_In santiy');
ok(nqp::div_In(box(1234500), box(100)) == 12345, 'div_In sanity');
my $n := nqp::div_In(
nqp::pow_I(box(203), box(200), $n_type, $bi_type),
nqp::pow_I(box(200), box(200), $n_type, $bi_type),
);

my $huge := nqp::pow_I(box(10), box(300), $n_type, $bi_type);

ok(nqp::div_In(box(1), $huge) == 1e-300, 'super small result from div_In work');
ok(nqp::div_In(box(-1), box(5)) == -0.2, 'div_In -1 by 5');
ok(nqp::div_In(box(-1), box(20)) == -0.05, 'div_In -1 by 20');
ok(nqp::div_In(box(1), box(-200)) == -0.005, 'div_In 1 by -20');

ok(nqp::abs_n($n - 19.6430286394751) < 1e-10, 'div_In with big numbers');

my $maxRand := nqp::fromstr_I('10000000000000000000000000000000000000000', $bi_type);
Expand Down
2 changes: 1 addition & 1 deletion tools/build/MOAR_REVISION
@@ -1 +1 @@
2017.12.1-30-ged7c1234
2017.12.1-34-g4a0a912

0 comments on commit c11e211

Please sign in to comment.