Skip to content

Commit 19f1639

Browse files
committed
[bigint] fix detection of negative numbers from binary ops
This should fix RT #109740
1 parent 2208373 commit 19f1639

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/ops/nqp_bigint.ops

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ static void grow_and_negate(mp_int *a, int size, mp_int *b) {
8989
mp_add_d(b, 1, b);
9090
}
9191

92+
9293
static void two_complement_bitop(mp_int *a, mp_int *b, mp_int *c,
9394
int (*mp_bitop)(mp_int *, mp_int *, mp_int *)) {
9495
mp_int d;
@@ -104,7 +105,7 @@ static void two_complement_bitop(mp_int *a, mp_int *b, mp_int *c,
104105
grow_and_negate(b, USED(a), &d);
105106
mp_bitop(a, &d, c);
106107
}
107-
if (DIGIT(c, USED(c) - 1) & (MP_MASK > 1)) {
108+
if (DIGIT(c, USED(c) - 1) & ((mp_digit)1<<(mp_digit)(DIGIT_BIT - 1))) {
108109
grow_and_negate(c, c->used, &d);
109110
mp_copy(&d, c);
110111
mp_neg(c, c);

t/nqp/60-bigint.t

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

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

66
my $knowhow := pir::get_knowhow__P();
77
my $bi_type := $knowhow.new_type(:name('TestBigInt'), :repr('P6bigint'));
@@ -35,6 +35,8 @@ ok(iseq(nqp::bitxor_I(box(0xdead), box(0xbeef), $one), 0x6042), 'bit xor');
3535

3636
ok(iseq(nqp::bitneg_I(box(-123), $one), 122), 'bit negation');
3737

38+
ok(iseq(nqp::bitand_I(pir::nqp_bigint_from_str__PSP('-1073741825', $one), $one, $one), 1),
39+
'Bit ops (RT 109740)');
3840

3941
# Now we'll create a type that boxes a P6bigint.
4042
my $bi_boxer := $knowhow.new_type(:name('TestPerl6Int'), :repr('P6opaque'));

0 commit comments

Comments
 (0)