[gcalctool] Remove negative sign from numbers rounded to zero. This is only a partial fix as the error value is



commit 6fd7e874611328e46dd291323b59798f867aa89c
Author: Robert Ancell <robert ancell gmail com>
Date:   Fri May 15 14:18:27 2009 +1000

    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)
---
 ChangeLog                |    2 ++
 src/mp-convert.c         |   18 +++++++++---------
 src/mp-equation-parser.y |    4 ++--
 3 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9c71bd1..99aa872 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,6 +10,8 @@ gcalctool change history.
 2009-05-15 Robert Ancell <robert ancell gmail com>
 
     * Made parser reentrant and part of MP code (Robert Ancell)
+    * 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)
 
 2009-05-11 Robert Ancell <robert ancell gmail com>
 
diff --git a/src/mp-convert.c b/src/mp-convert.c
index c9d573f..958feba 100644
--- a/src/mp-convert.c
+++ b/src/mp-convert.c
@@ -547,18 +547,12 @@ mp_cast_to_string(const MPNumber *MPnumber, int base, int accuracy, char *buffer
         end--;
     }
    
-    /* Stop if there is no fractional component or not showing fractional part */
-    if ((mp_is_zero(&fractional_component) && !v->display.show_zeroes) || accuracy == 0) {
-        *optr = '\0';
-        return;
-    }
-   
     last_non_zero = optr;
     *optr++ = '.';
    
     /* Write out the fractional component */
     mp_set_from_mp(&fractional_component, &temp);
-    do {
+    while (!mp_is_zero(&temp) && accuracy > 0) {
         int d;
         MPNumber digit;
 
@@ -577,13 +571,19 @@ mp_cast_to_string(const MPNumber *MPnumber, int base, int accuracy, char *buffer
             last_non_zero = optr;
         mp_subtract(&temp, &digit, &temp);
         accuracy--;
-    } while (!mp_is_zero(&temp) && accuracy > 0);
+    }
 
     /* Strip trailing zeroes */
-    if (!v->display.show_zeroes)
+    if (!v->display.show_zeroes || accuracy == 0)
        optr = last_non_zero;
 
     *optr = '\0';
+    
+    /* Remove negative sign if the number was rounded down to zero */
+    if (strcmp(buffer, "-0") == 0) {
+        buffer[0] = '0';
+        buffer[1] = '\0';
+    }
 }
 
 
diff --git a/src/mp-equation-parser.y b/src/mp-equation-parser.y
index 81e2234..d41c1cb 100644
--- a/src/mp-equation-parser.y
+++ b/src/mp-equation-parser.y
@@ -25,8 +25,8 @@
 #include <math.h>
 #include <errno.h>
 
-#include "calctool.h"
-#include "register.h"
+#include "calctool.h" // FIXME: Can be removed soon
+#include "register.h" // FIXME: Can be removed soon
 #include "mp-equation.h"
 #include "mp-equation-parser.h"
 #include "mp-equation-lexer.h"



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