[gnome-calculator] Fixed for negative exponents in modular exponentiation



commit 85560404c6ba45ee76df13820ac7806fdf209079
Author: Garima Joshi <garimajoshi3 yahoo in>
Date:   Mon May 20 02:37:25 2013 +0530

    Fixed for negative exponents in modular exponentiation

 src/number.vala |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
---
diff --git a/src/number.vala b/src/number.vala
index 12d52ef..4f40de1 100644
--- a/src/number.vala
+++ b/src/number.vala
@@ -1174,9 +1174,11 @@ public class Number
     /* Sets z = x ^ y mod p */
     public Number modular_exponentiation (Number exp, Number mod)
     {
+        var base_value = this.copy ();
+        if (exp.is_negative ())
+            base_value = base_value.reciprocal ();
+        var exp_value = exp.abs ();
         var ans = new Number.integer (1);
-        var base_value = modulus_divide (mod);
-        var exp_value = exp.copy ();
         var two = new Number.integer (2);
         while (!exp_value.is_zero ())
         {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]