[gcalctool/gnome-2-26] Remove negative sign from numbers rounded to zero. This is only a partial fix as the error value is
- From: Robert Ancell <rancell src gnome org>
- To: svn-commits-list gnome org
- Subject: [gcalctool/gnome-2-26] Remove negative sign from numbers rounded to zero. This is only a partial fix as the error value is
- Date: Sun, 17 May 2009 00:58:44 -0400 (EDT)
commit 3438626afb6865d5aa9fe69e567c6cde7c655889
Author: Robert Ancell <robert ancell gmail com>
Date: Sun May 17 14:34:45 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 | 5 +++++
gcalctool/mp-convert.c | 35 ++++++++++++++++++++++++-----------
2 files changed, 29 insertions(+), 11 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 49faf31..d468008 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,11 @@
gcalctool change history.
=========================
+2009-05-17 Robert Ancell <robert ancell gmail com>
+
+ * 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-04-20 Robert Ancell <robert ancell gmail com>
* Fix missing license text in about dialog (Robert Ancell, Bug #579174)
diff --git a/gcalctool/mp-convert.c b/gcalctool/mp-convert.c
index 4351fb1..09d3d2a 100644
--- a/gcalctool/mp-convert.c
+++ b/gcalctool/mp-convert.c
@@ -483,10 +483,11 @@ void
mp_cast_to_string(char *target, int target_len, const int *MPnumber, int base, int accuracy)
{
static char digits[] = "0123456789ABCDEF";
- char *optr, *start, *end, *last_non_zero;
+ char *optr, *start, *end, *stopper, *last_non_zero;
int number[MP_SIZE], integer_component[MP_SIZE], fractional_component[MP_SIZE], MPbase[MP_SIZE], temp[MP_SIZE];
optr = target;
+ stopper = target + target_len - 1;
/* Insert sign */
if (mp_is_negative(MPnumber)) {
@@ -519,13 +520,19 @@ mp_cast_to_string(char *target, int target_len, const int *MPnumber, int base, i
mp_subtract(temp, t2, t3);
mpcmim(t3, t3);
+
+ if (optr == stopper) {
+ mperr("Number too big to represent");
+ *optr = '\0';
+ return;
+ }
*optr++ = digits[mp_cast_to_int(t3)];
mp_set_from_mp(t, temp);
} while (!mp_is_zero(temp));
- end = optr - 1;
/* Reverse digits */
+ end = optr - 1;
while(start < end) {
char t;
t = *start;
@@ -535,18 +542,12 @@ mp_cast_to_string(char *target, int target_len, const int *MPnumber, int base, i
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;
int digit[MP_SIZE];
@@ -554,18 +555,30 @@ mp_cast_to_string(char *target, int target_len, const int *MPnumber, int base, i
mpcmim(temp, digit);
d = mp_cast_to_int(digit);
+ if (optr == stopper) {
+ mperr("Number too big to represent");
+ *optr = '\0';
+ return;
+ }
*optr++ = digits[d];
+
if(d != 0)
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(target, "-0") == 0) {
+ target[0] = '0';
+ target[1] = '\0';
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]