From 864038dab78afb01d7736faae0de58510d40e7c1 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 31 Mar 2014 02:12:40 +0300 Subject: [PATCH] objfloat: Make sure that floats always have dot (for C "double" type case). This matches CPython behavior and hopefully can be treated as general Python semantics. --- py/objfloat.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/py/objfloat.c b/py/objfloat.c index 5e4d05f172..d8ac96c0b4 100644 --- a/py/objfloat.c +++ b/py/objfloat.c @@ -1,4 +1,6 @@ #include +#include +#include #include #include @@ -23,7 +25,13 @@ STATIC void float_print(void (*print)(void *env, const char *fmt, ...), void *en format_float(o->value, buf, sizeof(buf), 'g', 6, '\0'); print(env, "%s", buf); #else - print(env, "%.8g", (double) o->value); + char buf[32]; + sprintf(buf, "%.8g", (double) o->value); + print(env, buf); + if (strchr(buf, '.') == NULL) { + // Python floats always have decimal point + print(env, ".0"); + } #endif }