summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkrasimir <krasimir@chalmers.se>2016-04-13 14:30:40 +0000
committerkrasimir <krasimir@chalmers.se>2016-04-13 14:30:40 +0000
commite8e52de6b94eb9f1974ce2c4c1402c7722c23a9a (patch)
tree4bd32eb5cc73d0d58182444f859e89a11c747325 /src
parentc0344e936a30fb46d28f5dfa27623efc8c5c4dc5 (diff)
locale independent printing for doubles when they are part of an abstract expression
Diffstat (limited to 'src')
-rw-r--r--src/runtime/c/gu/string.c23
-rw-r--r--src/runtime/c/gu/string.h3
-rw-r--r--src/runtime/c/pgf/expr.c2
3 files changed, 27 insertions, 1 deletions
diff --git a/src/runtime/c/gu/string.c b/src/runtime/c/gu/string.c
index 0947cf9e0..5a31c8806 100644
--- a/src/runtime/c/gu/string.c
+++ b/src/runtime/c/gu/string.c
@@ -217,6 +217,29 @@ gu_string_to_double(GuString s, double *res)
return true;
}
+void
+gu_double_to_string(double val, GuOut* out, GuExn* err)
+{
+ int ival = (int) val;
+ gu_printf(out, err, "%d", ival);
+ val -= ival;
+
+ if (val < 0)
+ val = -val;
+
+ if (val != 0) {
+ gu_putc('.', out, err);
+
+ while (val > 0.000001) // process remaining digits
+ {
+ val = val * 10;
+ ival = (int) val;
+ gu_printf(out, err, "%d", ival);
+ val -= ival;
+ }
+ }
+}
+
bool
gu_string_is_prefix(GuString s1, GuString s2)
{
diff --git a/src/runtime/c/gu/string.h b/src/runtime/c/gu/string.h
index e4729239c..4064286a9 100644
--- a/src/runtime/c/gu/string.h
+++ b/src/runtime/c/gu/string.h
@@ -48,6 +48,9 @@ gu_string_to_int(GuString s, int *res);
bool
gu_string_to_double(GuString s, double *res);
+void
+gu_double_to_string(double val, GuOut* out, GuExn* err);
+
bool
gu_string_is_prefix(GuString s1, GuString s2);
diff --git a/src/runtime/c/pgf/expr.c b/src/runtime/c/pgf/expr.c
index c06efd737..ebb3e8138 100644
--- a/src/runtime/c/pgf/expr.c
+++ b/src/runtime/c/pgf/expr.c
@@ -1189,7 +1189,7 @@ pgf_print_literal(PgfLiteral lit,
}
case PGF_LITERAL_FLT: {
PgfLiteralFlt* lit = ei.data;
- gu_printf(out, err, "%lg", lit->val);
+ gu_double_to_string(lit->val, out, err);
break;
}
default: