[gcalctool/gnome-3-0] Fix 0^n generating error for fractional n



commit c43d0aab08b77f5d6f9ab73147bbf573f473f930
Author: Robert Ancell <robert ancell canonical com>
Date:   Wed Apr 20 12:25:28 2011 +1000

    Fix 0^n generating error for fractional n

 NEWS                   |    1 +
 src/mp.c               |    7 ++++---
 src/test-mp-equation.c |    1 +
 3 files changed, 6 insertions(+), 3 deletions(-)
---
diff --git a/NEWS b/NEWS
index b24b91d..d2d367e 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ Overview of changes in gcalctool 6.0.1
       (Bug #647327)
     * Fix crash when not all currencies downloaded
     * Fix bit editor (Bug #646142)
+    * Fix 0^n generating error for fractional n (Bug #634066)
 
 Overview of changes in gcalctool 6.0.0
 
diff --git a/src/mp.c b/src/mp.c
index 8e9ede6..ae9caf9 100644
--- a/src/mp.c
+++ b/src/mp.c
@@ -1678,10 +1678,11 @@ mp_pwr(const MPNumber *x, const MPNumber *y, MPNumber *z)
         return;
     }*/
 
-    /* 0^-y illegal */
-    if (mp_is_zero(x) && y->sign < 0) {
-        mperr(_("The power of zero is undefined for a negative exponent"));
+    /* 0^y = 0, 0^-y undefined */  
+    if (mp_is_zero(x)) {
         mp_set_from_integer(0, z);
+        if (y->sign < 0)
+            mperr(_("The power of zero is undefined for a negative exponent"));
         return;
     }
 
diff --git a/src/test-mp-equation.c b/src/test-mp-equation.c
index a046816..f12b998 100644
--- a/src/test-mp-equation.c
+++ b/src/test-mp-equation.c
@@ -391,6 +391,7 @@ test_equations()
     test("|1â??3|²", "4", 0);
     test("|x|²", "4", 0);
     test("0^0", "1", 0);
+    test("0^0.5", "0", 0);
     test("2^0", "1", 0);
     test("2^1", "2", 0);
     test("2^2", "4", 0);



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