Skip to content

Commit e694ab9

Browse files
committed
Merge branch 'master' into bs
2 parents c35d3cd + bcde9c4 commit e694ab9

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
=head1 NQP - Not Quite Perl (6)
22

3-
NQP is Copyright (C) 2009-2011 by The Perl Foundation. See F<LICENSE>
3+
NQP is Copyright (C) 2009-2012 by The Perl Foundation. See F<LICENSE>
44
for licensing details.
55

66
This is "Not Quite Perl" -- a compiler for quickly generating PIR

src/PAST/NQP.pir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ entry to produce the node to be returned.
450450
maphash['mul_n'] = 'mul__Nnn'
451451
maphash['div_i'] = 'div__Iii'
452452
maphash['div_I'] = 'nqp_bigint_div__PPPP'
453+
maphash['div_In'] = 'nqp_bigint_div_num__NPP'
453454
maphash['div_n'] = 'div__Nnn'
454455
maphash['mod_i'] = 'mod__Iii'
455456
maphash['mod_I'] = 'nqp_bigint_mod__PPPP'

src/ops/nqp_bigint.ops

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,25 @@ inline op nqp_bigint_from_num(out PMC, in NUM, in PMC) :base_core {
304304
from_num($2, get_bigint(interp, $1));
305305
}
306306

307+
inline op nqp_bigint_div_num(out NUM, in PMC, in PMC) :base_core {
308+
mp_int *a = get_bigint(interp, $2);
309+
mp_int *b = get_bigint(interp, $3);
310+
311+
int max_size = DIGIT_BIT * MAX(USED(a), USED(b));
312+
if (max_size > 1023) {
313+
mp_int reduced_a, reduced_b;
314+
mp_init(&reduced_a);
315+
mp_init(&reduced_b);
316+
mp_div_2d(a, max_size - 1023, &reduced_a, NULL);
317+
mp_div_2d(b, max_size - 1023, &reduced_b, NULL);
318+
$1 = mp_get_double(&reduced_a) / mp_get_double(&reduced_b);
319+
mp_clear(&reduced_a);
320+
mp_clear(&reduced_b);
321+
} else {
322+
$1 = mp_get_double(a) / mp_get_double(b);
323+
}
324+
}
325+
307326
inline op nqp_bigint_shr(out PMC, in PMC, in INT, in PMC) :base_core {
308327
mp_int *a = get_bigint(interp, $2);
309328
$1 = REPR($4)->allocate(interp, STABLE($4));

t/nqp/60-bigint.t

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#! nqp
22
use nqpmo;
33

4-
plan(32);
4+
plan(34);
55

66
my $knowhow := pir::get_knowhow__P();
77
my $bi_type := $knowhow.new_type(:name('TestBigInt'), :repr('P6bigint'));
@@ -93,3 +93,10 @@ ok(str(nqp::expmod_I(
9393
nqp::fromstr_I('10000000000000000000000000000000000000000', $bi_type),
9494
$bi_type,
9595
)) eq '1527229998585248450016808958343740453059', 'nqp::expmod_I');
96+
97+
ok(nqp::div_In(box(1234500), box(100)) == 12345, 'div_In santiy');
98+
my $n := nqp::div_In(
99+
nqp::pow_I(box(203), box(200), $bi_type, $bi_type),
100+
nqp::pow_I(box(200), box(200), $bi_type, $bi_type),
101+
);
102+
ok(nqp::abs_n($n - 19.6430286394751) < 1e-10, 'div_In with big numbers');

0 commit comments

Comments
 (0)