diff options
Diffstat (limited to 'src/runtime/c/gu')
| -rw-r--r-- | src/runtime/c/gu/string.c | 23 | ||||
| -rw-r--r-- | src/runtime/c/gu/string.h | 3 |
2 files changed, 26 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) { 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); |
