From 4cd7e62ce41c6d96bd42771e10315e5f0fbf4286 Mon Sep 17 00:00:00 2001 From: skylarmt Date: Mon, 13 Apr 2015 12:08:20 -0600 Subject: [PATCH] Add gcd(a,b) and powermod(a,b,m). --- src/net/apocalypselabs/symat/Functions.java | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/net/apocalypselabs/symat/Functions.java b/src/net/apocalypselabs/symat/Functions.java index 153a945..52c7d3b 100644 --- a/src/net/apocalypselabs/symat/Functions.java +++ b/src/net/apocalypselabs/symat/Functions.java @@ -174,6 +174,24 @@ public class Functions { return fact.toString(); } + /** + * Take (a^b) mod m. + * @param a Number + * @param b Exponent + * @param m Modulus + * @return pow(a,b)%m. + */ + public double powermod(double a, double b, double m) { + return (pow(a, b) % m + m) % m; + } + + public int gcd(int a, int b) { + if (b == 0) { + return a; + } + return gcd(b, a % b); + } + /** * Differentiate the function with respect to idv. * @@ -862,7 +880,7 @@ public class Functions { public void setLang(String l) { lang = l; } - + /** * This class finds permutations of an array. *