[gnome-calculator] Fix for improving integer exponentiation
- From: Arth Patel <arthpatel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calculator] Fix for improving integer exponentiation
- Date: Wed, 22 May 2013 10:24:07 +0000 (UTC)
commit 5ee866bf6ea1a566df98b66633e5667cc8ff86dd
Author: Garima Joshi <garimajoshi3 yahoo in>
Date: Wed May 22 14:53:47 2013 +0530
Fix for improving integer exponentiation
src/number.vala | 11 +++++++----
1 files changed, 7 insertions(+), 4 deletions(-)
---
diff --git a/src/number.vala b/src/number.vala
index 5805502..4672e14 100644
--- a/src/number.vala
+++ b/src/number.vala
@@ -931,11 +931,14 @@ public class Number
else
t = this;
- /* Multply x n times */
- // FIXME: Can do z = z.multiply (z) until close to answer (each call doubles number of multiples) */
var z = new Number.integer (1);
- for (var i = 0; i < n; i++)
- z = z.multiply (t);
+ while (n != 0)
+ {
+ if (n % 2 == 1)
+ z = z.multiply (t);
+ t = t.multiply (t);
+ n = n / 2;
+ }
return z;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]