Skip to content
Browse files

Add facility for negating the number to the copy constructor.

  • Loading branch information...
1 parent 8493913 commit 2a55b1162985d31e3327bcd6af9efa8fb6f684c4 @colomon committed May 13, 2011
Showing with 8 additions and 2 deletions.
  1. +2 −2 lib/Math/BigInt.pm
  2. +6 −0 t/01-basic.t
View
4 lib/Math/BigInt.pm
@@ -25,10 +25,10 @@ class Math::BigInt does Real {
has $.bd;
has $.negative;
- multi method new(Math::BigInt $other) {
+ multi method new(Math::BigInt $other, :$negate) {
my $bd = bdNew();
bdSetEqual($bd, $other.bd);
- self.bless(*, :$bd, :negative($other.negative));
+ self.bless(*, :$bd, :negative($negate ?? !$other.negative !! $other.negative));
}
multi method new(Str $digits) {
View
6 t/01-basic.t
@@ -53,6 +53,9 @@ plan *;
my $c = Math::BigInt.new($a);
isa_ok $c, Math::BigInt, "We successfully made a BigInt";
is ~$c, "1234567890098765432100123456789", "Stringifies properly";
+ my $d = Math::BigInt.new($a, :negate);
+ isa_ok $d, Math::BigInt, "We successfully made a BigInt";
+ is ~$d, "-1234567890098765432100123456789", "Stringifies properly";
}
{
@@ -69,6 +72,9 @@ plan *;
my $c = Math::BigInt.new($a);
isa_ok $c, Math::BigInt, "We successfully made a BigInt";
is ~$c, "-1234567890098765432100123456789", "Stringifies properly";
+ my $d = Math::BigInt.new($a, :negate);
+ isa_ok $d, Math::BigInt, "We successfully made a BigInt";
+ is ~$d, "1234567890098765432100123456789", "Stringifies properly";
}
{

0 comments on commit 2a55b11

Please sign in to comment.
Something went wrong with that request. Please try again.