[gcalctool] Show bit editor for numbers not in base 10



commit f5f054908c6a76f9314d9ce0f9028e77c01ac172
Author: Robert Ancell <robert ancell gmail com>
Date:   Mon Mar 1 11:00:10 2010 +1100

    Show bit editor for numbers not in base 10

 NEWS          |    4 +++-
 src/display.c |   37 ++++++++++++++++---------------------
 2 files changed, 19 insertions(+), 22 deletions(-)
---
diff --git a/NEWS b/NEWS
index 51711bf..e34eccf 100644
--- a/NEWS
+++ b/NEWS
@@ -3,7 +3,7 @@
  *  Copyright (c) 1987-2009 Sun Microsystems, Inc.
  *  All Rights Reserved.
  */
- 
+
 Overview of changes in gcalctool 5.29.92
 
     * Add shortcuts to change base (Ctrl+B, Ctrl+O, Ctrl+D, Ctrl+H), and change
@@ -17,6 +17,8 @@ Overview of changes in gcalctool 5.29.92
 
     * Allow hexadecimal numbers to be entered in lower-case
 
+    * Make bit editor active for displayed numbers not in base 10
+
 Overview of changes in gcalctool 5.29.91
 
     * Fix bug where backspace deletes all input in locales with no thousands
diff --git a/src/display.c b/src/display.c
index d76f61d..a71d78e 100644
--- a/src/display.c
+++ b/src/display.c
@@ -144,16 +144,17 @@ get_expression(GCDisplay *display)
 gboolean
 display_get_integer(GCDisplay *display, gint64 *value)
 {
-    gchar *endptr;
+    MPNumber t, min, max;
 
-    if (display_is_result(display)) {
-        *value = mp_cast_to_int(display_get_answer(display));
-        return TRUE;
-    }
+    if (!display_is_usable_number(display, &t))
+        return FALSE;
 
-    *value = g_ascii_strtoll(get_text(display), &endptr, 10);
-    if(*endptr != '\0' || ((*value == G_MAXINT64 || *value == G_MININT64) && errno == ERANGE))
+    mp_set_from_integer(G_MININT64, &min);
+    mp_set_from_integer(G_MAXINT64, &max);
+    if (mp_is_less_than(&t, &min) || mp_is_greater_than(&t, &max))
         return FALSE;
+
+    *value = mp_cast_to_int(&t);
     return TRUE;
 }
 
@@ -161,23 +162,17 @@ display_get_integer(GCDisplay *display, gint64 *value)
 gboolean
 display_get_unsigned_integer(GCDisplay *display, guint64 *value)
 {
-    const char *text;
-    char buf[MAX_DISPLAY];
-    gchar *endptr;
+    MPNumber t, max;
 
-    text = get_text(display);
-    if (display_is_result(display)) {
-        display_make_number(display, buf, MAX_DISPLAY, display_get_answer(display));
-        text = buf;
-    }
-
-    /* strtoull() treats the string like a 2's complement number which is not what we want */
-    if(strncmp(text, "-", strlen("-")) == 0 || strncmp(text, "â??", strlen("â??")) == 0)
+    if (!display_is_usable_number(display, &t))
         return FALSE;
-
-    *value = g_ascii_strtoull(text, &endptr, 10);
-    if(*endptr != '\0' || (*value == G_MAXUINT64 && errno == ERANGE))
+  
+    mp_set_from_unsigned_integer(G_MAXUINT64, &max);
+    char string[MAX_DIGITS];
+    if (mp_is_negative(&t) || mp_is_greater_than(&t, &max))
         return FALSE;
+
+    *value = mp_cast_to_unsigned_int(&t);
     return TRUE;
 }
 



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