Permalink
Browse files

Add postfix:<¹> op to create a Math::BigInt with a minimum of fuss.

  • Loading branch information...
1 parent f0065f3 commit d559bd56ffdc42534f4751d46fe6b0f0cf2eed75 @colomon committed Jan 29, 2011
Showing with 9 additions and 1 deletion.
  1. +8 −0 lib/Math/BigInt.pm
  2. +1 −1 t/03-playing.t
View
8 lib/Math/BigInt.pm
@@ -50,6 +50,14 @@ class Math::BigInt does Real {
method succ(Math::BigInt $x:) { bdIncrement($x.bd); self; }
method pred(Math::BigInt $x:) { bdDecrement($x.bd); self; }
+
+ multi sub postfix:<¹>(Int $a) is export(:DEFAULT) {
+ Math::BigInt.new(~$a);
+ }
+
+ multi sub postfix:<¹>(Str $a) is export(:DEFAULT) {
+ Math::BigInt.new($a);
+ }
multi sub infix:<+>(Math::BigInt $a, Math::BigInt $b) is export(:DEFAULT) {
my $result = Math::BigInt.new("1");
View
2 t/03-playing.t
@@ -14,7 +14,7 @@ plan *;
}
{
- my @fib := Math::BigInt.new(1), Math::BigInt.new(1), *+* ... *;
+ my @fib := 1¹, 1¹, *+* ... *;
isa_ok @fib[200], Math::BigInt, "201st Fib is a BigInt";
is ~@fib[200], "453973694165307953197296969697410619233826",
"201st Fib is 453973694165307953197296969697410619233826";

0 comments on commit d559bd5

Please sign in to comment.