Skip to content

Commit 7de5377

Browse files
committed
objfloat: Try to achieve the same float printing format as CPython does.
Test usecase I used is print(time.time()) and print(time.time() - time.time()). On Linux/Glibc they now give the same output as CPython 3.3. Specifically, time.time() gives non-exponential output with 7 decimal digits, and subtraction gives exponential output e-06/e-07.
1 parent 599bbc1 commit 7de5377

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

py/objfloat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ STATIC void float_print(void (*print)(void *env, const char *fmt, ...), void *en
3030
}
3131
#else
3232
char buf[32];
33-
sprintf(buf, "%.8g", (double) o->value);
33+
sprintf(buf, "%.17g", (double) o->value);
3434
print(env, buf);
3535
if (strchr(buf, '.') == NULL) {
3636
// Python floats always have decimal point

0 commit comments

Comments
 (0)