[gcalctool] Fix i being incorrectly displayed. Needs more work
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcalctool] Fix i being incorrectly displayed. Needs more work
- Date: Thu, 27 Jan 2011 08:27:31 +0000 (UTC)
commit d1f682724f7a5370f5a206afef347052388898a1
Author: Robert Ancell <robert ancell canonical com>
Date: Thu Jan 27 18:27:23 2011 +1000
Fix i being incorrectly displayed. Needs more work
src/mp-serializer.c | 58 +++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 52 insertions(+), 6 deletions(-)
---
diff --git a/src/mp-serializer.c b/src/mp-serializer.c
index 9d2b052..b19b0b4 100644
--- a/src/mp-serializer.c
+++ b/src/mp-serializer.c
@@ -223,18 +223,14 @@ mp_cast_to_string(MpSerializer *serializer, const MPNumber *x)
}
-static gchar *
-mp_cast_to_exponential_string(MpSerializer *serializer, const MPNumber *x, gboolean eng_format)
+static void
+mp_cast_to_exponential_string_real(MpSerializer *serializer, const MPNumber *x, GString *string, gboolean eng_format)
{
gchar *fixed, *c;
MPNumber t, z, base, base3, base10, base10inv, mantissa;
int exponent = 0;
- GString *string;
- gchar *result;
const gchar *super_digits[] = {"�", "¹", "²", "³", "�", "�", "�", "�", "�", "�"};
- string = g_string_sized_new(1024);
-
mp_abs(x, &z);
if (mp_is_negative(x))
g_string_append(string, "â??");
@@ -287,6 +283,56 @@ mp_cast_to_exponential_string(MpSerializer *serializer, const MPNumber *x, gbool
g_string_append(string, super_digits[*c - '0']);
g_free (super_value);
}
+}
+
+
+static gchar *
+mp_cast_to_exponential_string(MpSerializer *serializer, const MPNumber *x, gboolean eng_format)
+{
+ GString *string;
+ MPNumber x_real;
+ gchar *result;
+
+ string = g_string_sized_new(1024);
+
+ mp_real_component(x, &x_real);
+ mp_cast_to_exponential_string_real(serializer, &x_real, string, eng_format);
+ if (mp_is_complex(x)) {
+ GString *s;
+ gboolean force_sign = TRUE;
+ MPNumber x_im;
+
+ mp_imaginary_component(x, &x_im);
+
+ if (strcmp(string->str, "0") == 0) {
+ g_string_assign(string, "");
+ force_sign = FALSE;
+ }
+
+ s = g_string_sized_new(1024);
+ mp_cast_to_exponential_string_real(serializer, &x_im, s, eng_format);
+ if (strcmp(s->str, "0") == 0 || strcmp(s->str, "+0") == 0 || strcmp(s->str, "â??0") == 0) {
+ /* Ignore */
+ }
+ else if (strcmp(s->str, "1") == 0) {
+ g_string_append(string, "i");
+ }
+ else if (strcmp(s->str, "+1") == 0) {
+ g_string_append(string, "+i");
+ }
+ else if (strcmp(s->str, "â??1") == 0) {
+ g_string_append(string, "â??i");
+ }
+ else {
+ if (strcmp(s->str, "+0") == 0)
+ g_string_append(string, "+");
+ else if (strcmp(s->str, "0") != 0)
+ g_string_append(string, s->str);
+
+ g_string_append(string, "i"); // FIXME: Insert before the *10^
+ }
+ g_string_free(s, TRUE);
+ }
result = g_strndup(string->str, string->len + 1);
g_string_free(string, TRUE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]