diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-03-31 02:12:40 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-03-31 02:23:57 +0300 |
commit | 864038dab78afb01d7736faae0de58510d40e7c1 (patch) | |
tree | c79748792838c080bd68cb082a41ff58d05ed0c0 | |
parent | a8e60c1fdee248bda55e9e6e718e05d78c93e115 (diff) | |
download | micropython-864038dab78afb01d7736faae0de58510d40e7c1.tar.gz micropython-864038dab78afb01d7736faae0de58510d40e7c1.zip |
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.
-rw-r--r-- | py/objfloat.c | 10 |
1 files changed, 9 insertions, 1 deletions
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 <stdlib.h> +#include <stdio.h> +#include <string.h> #include <assert.h> #include <math.h> @@ -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 } |