[gnome-calculator] Do not assume octal base for binary numbers (fixes #101)
- From: Robert Roth <robertroth src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calculator] Do not assume octal base for binary numbers (fixes #101)
- Date: Tue, 26 Mar 2019 23:08:10 +0000 (UTC)
commit e39c7bd3d18835ebd904f2f13a87593c25b29c03
Author: Robert Roth <robert roth off gmail com>
Date: Wed Mar 27 01:07:52 2019 +0200
Do not assume octal base for binary numbers (fixes #101)
lib/number.vala | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
---
diff --git a/lib/number.vala b/lib/number.vala
index 9ca74180..57631d1a 100644
--- a/lib/number.vala
+++ b/lib/number.vala
@@ -1128,11 +1128,15 @@ private static int parse_literal_prefix (string str, ref int prefix_len)
{
unichar c;
bool all_digits = true;
+ bool all_binary_digits = true;
for (int i = 2; str.get_next_char (ref i, out c) && all_digits;)
all_digits = c.isdigit ();
- if (all_digits)
+ for (int i = 2; str.get_next_char (ref i, out c) && all_binary_digits;)
+ all_binary_digits = (c == '0' || c == '1');
+
+ if (all_digits && !all_binary_digits)
new_base = 8;
}
@@ -1180,12 +1184,16 @@ public Number? mp_set_from_string (string str, int default_base = 10)
literal_base = parse_literal_prefix (str, ref base_prefix);
+ info ("number_base is %d", number_base);
+
if (number_base != 0 && literal_base != 0 && literal_base != number_base)
return null;
+ info ("literal_base is %d", literal_base);
if (number_base == 0)
number_base = (literal_base != 0) ? literal_base : default_base;
+ info ("number_base is %d", number_base);
/* Check if this has a sign */
var negate = false;
index = base_prefix;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]