Skip to content

Instantly share code, notes, and snippets.

@grondilu
Created July 30, 2013 13:26
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/6112872 to your computer and use it in GitHub Desktop.
Save grondilu/6112872 to your computer and use it in GitHub Desktop.
second attempt of ethiopian exponentiation
From 7993316217fc1e137a757ab710077e68cb7bb350 Mon Sep 17 00:00:00 2001
From: Lucien Grondin <grondilu@yahoo.fr>
Date: Tue, 30 Jul 2013 15:23:07 +0200
Subject: [PATCH 2/2] second attempt of ethiopian exponentiation
---
src/core/Complex.pm | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/core/Complex.pm b/src/core/Complex.pm
index a775bbf..74fcdf1 100644
--- a/src/core/Complex.pm
+++ b/src/core/Complex.pm
@@ -401,9 +401,11 @@ multi sub infix:</>(Real \a, Complex:D \b) returns Complex:D {
}
multi sub infix:<**>(Complex:D \z, Int:D \n where \n > 0) {
- my @n = n, * div 2 ...^ 0;
- my @z := z, { $^z * $z } ... *;
- [*] map *.value, grep *.key % 2, (@n Z=> @z);
+ my $z = z;
+ [*] 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 {
--
1.8.1.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment