Skip to content

Commit 864038d

Browse files
committed
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.
1 parent a8e60c1 commit 864038d

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

py/objfloat.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#include <stdlib.h>
2+
#include <stdio.h>
3+
#include <string.h>
24
#include <assert.h>
35
#include <math.h>
46

@@ -23,7 +25,13 @@ STATIC void float_print(void (*print)(void *env, const char *fmt, ...), void *en
2325
format_float(o->value, buf, sizeof(buf), 'g', 6, '\0');
2426
print(env, "%s", buf);
2527
#else
26-
print(env, "%.8g", (double) o->value);
28+
char buf[32];
29+
sprintf(buf, "%.8g", (double) o->value);
30+
print(env, buf);
31+
if (strchr(buf, '.') == NULL) {
32+
// Python floats always have decimal point
33+
print(env, ".0");
34+
}
2735
#endif
2836
}
2937

0 commit comments

Comments
 (0)