summaryrefslogtreecommitdiff
path: root/src/runtime/c/gu/string.c
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/runtime/c/gu/string.c
parentc0344e936a30fb46d28f5dfa27623efc8c5c4dc5 (diff)
locale independent printing for doubles when they are part of an abstract expression
Diffstat (limited to 'src/runtime/c/gu/string.c')
-rw-r--r--src/runtime/c/gu/string.c23
1 files changed, 23 insertions, 0 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)
{