Skip to content

Instantly share code, notes, and snippets.

@grondilu
Created July 30, 2013 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grondilu/6112994 to your computer and use it in GitHub Desktop.
Save grondilu/6112994 to your computer and use it in GitHub Desktop.
ethiopian exponantiation
From 94aca2cbcba52f51708ae37904234096ec8781c2 Mon Sep 17 00:00:00 2001
From: Lucien Grondin <grondilu@yahoo.fr>
Date: Tue, 30 Jul 2013 15:38:18 +0200
Subject: [PATCH] first commit
---
src/core/Complex.pm | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/src/core/Complex.pm b/src/core/Complex.pm
index d5e0ada..00c1f10 100644
--- a/src/core/Complex.pm
+++ b/src/core/Complex.pm
@@ -400,6 +400,13 @@ multi sub infix:</>(Real \a, Complex:D \b) returns Complex:D {
Complex.new(a, 0) / b;
}
+multi sub infix:<**>(Complex:D $z is copy, Int:D \n where \n > 0) {
+ [*] gather for n, * div 2 ...^ 0 -> $n {
+ take $z unless $n %% 2;
+ $z *= $z;
+ }
+}
+multi sub infix:<**>(Complex:D \z, Int:D \n where n < 0) { 1/ z**(-n) }
multi sub infix:<**>(Complex:D \a, Complex:D \b) returns Complex:D {
(a.re == 0e0 && a.im == 0e0) ?? Complex.new(0e0, 0e0) !! (b * a.log).exp
}
--
1.8.1.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment