[gcalctool/gnome-2-26] Support odd roots of negative numbers (Robert Ancell, Bug #576973)



commit 7e7f20576f5c712690d87e0c5b6cea51cb0029dc
Author: Robert Ancell <robert ancell gmail com>
Date:   Sun May 17 14:35:28 2009 +1000

    Support odd roots of negative numbers (Robert Ancell, Bug #576973)
---
 ChangeLog      |    1 +
 gcalctool/mp.c |    7 ++++++-
 2 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index d468008..fe3e54d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -11,6 +11,7 @@ gcalctool change history.
 
     * Remove negative sign from numbers rounded to zero.  This is only a partial fix as
       the error value is still visible in scientific notation (Robert Ancell, Bug #560802)
+    * Support odd roots of negative numbers (Robert Ancell, Bug #576973)
 
 2009-04-20 Robert Ancell <robert ancell gmail com>
 
diff --git a/gcalctool/mp.c b/gcalctool/mp.c
index dc90fd4..ca13c38 100644
--- a/gcalctool/mp.c
+++ b/gcalctool/mp.c
@@ -2463,7 +2463,12 @@ mp_xpowy(int x[MP_SIZE], int y[MP_SIZE], int res[MP_SIZE])
     if (mp_is_integer(y)) {
         mppwr(x, mp_cast_to_int(y), res);
     } else {
-        mppwr2(x, y, res);
+        int reciprocal[MP_SIZE];
+        mp_reciprocal(y, reciprocal);
+        if (mp_is_integer(reciprocal))
+            mp_root(x, mp_cast_to_int(reciprocal), res);
+        else
+            mppwr2(x, y, res);
     }
 }
 



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