Skip to content

Commit

Permalink
Add infix:<%>.
Browse files Browse the repository at this point in the history
  • Loading branch information
colomon committed Jan 29, 2011
1 parent 2cfe839 commit 17ff128
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/Math/BigInt.pm
Expand Up @@ -103,6 +103,18 @@ class Math::BigInt does Real {
bdMultiply($result.bd, Math::BigInt.new($a).bd, $b.bd);
$result;
}

multi sub infix:<%>(Math::BigInt $a, Math::BigInt $b) is export(:DEFAULT) {
my $result = Math::BigInt.new("1");
bdModulo($result.bd, $a.bd, $b.bd);
$result;
}

multi sub infix:<%>(Math::BigInt $a, Int $b) is export(:DEFAULT) {
my $result = Math::BigInt.new("1");
bdModulo($result.bd, $a.bd, Math::BigInt.new($b).bd);
$result.Int;
}
}


Expand Down
16 changes: 16 additions & 0 deletions t/02-arith.t
Expand Up @@ -93,6 +93,22 @@ plan *;
is $a, "800000000000000000", "and it's 800000000000000000";
}

# modulo BigInts and BigInts
{
my $a = Math::BigInt.new("43452454234524532423");
my $b = Math::BigInt.new("2");

my $c = $a % $b;
isa_ok $c, Math::BigInt, "43452454234524532423 % 2 is a BigInt";
is $c, "1", "and it's 1";

$c = $a % 2;
isa_ok $c, Int, "43452454234524532423 % 2 is an Int";
is $c, 1, "and it's 1";
}






Expand Down

0 comments on commit 17ff128

Please sign in to comment.