Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[bigint] fix detection of negative numbers from binary ops
This should fix RT #109740
  • Loading branch information
moritz committed Feb 8, 2012
1 parent 2208373 commit 19f1639
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/ops/nqp_bigint.ops
Expand Up @@ -89,6 +89,7 @@ static void grow_and_negate(mp_int *a, int size, mp_int *b) {
mp_add_d(b, 1, b);
}


static void two_complement_bitop(mp_int *a, mp_int *b, mp_int *c,
int (*mp_bitop)(mp_int *, mp_int *, mp_int *)) {
mp_int d;
Expand All @@ -104,7 +105,7 @@ static void two_complement_bitop(mp_int *a, mp_int *b, mp_int *c,
grow_and_negate(b, USED(a), &d);
mp_bitop(a, &d, c);
}
if (DIGIT(c, USED(c) - 1) & (MP_MASK > 1)) {
if (DIGIT(c, USED(c) - 1) & ((mp_digit)1<<(mp_digit)(DIGIT_BIT - 1))) {
grow_and_negate(c, c->used, &d);
mp_copy(&d, c);
mp_neg(c, c);
Expand Down
4 changes: 3 additions & 1 deletion t/nqp/60-bigint.t
@@ -1,7 +1,7 @@
#! nqp
use nqpmo;

plan(31);
plan(32);

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

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

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

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

0 comments on commit 19f1639

Please sign in to comment.