From b0eee4afe5a0eb4136dcf20f781ce4dacbb9c003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Moskal?= Date: Tue, 31 Jul 2018 14:41:31 -0700 Subject: [PATCH] Convert int-to-string directly, without double, see #999 (#1009) --- libs/core/core.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libs/core/core.cpp b/libs/core/core.cpp index 73c6fe91..0e2b83c7 100644 --- a/libs/core/core.cpp +++ b/libs/core/core.cpp @@ -4,10 +4,8 @@ using namespace std; - #define p10(v) __builtin_powi(10, v) - namespace pxt { static HandlerBinding *handlerBindings; @@ -610,7 +608,7 @@ void mycvt(double d, char *buf) { int sig = 0; while (sig < 17 || beforeDot > 0) { - //printf("%f sig=%d bd=%d\n", d, sig, beforeDot); + // printf("%f sig=%d bd=%d\n", d, sig, beforeDot); int c = (int)d; *buf++ = '0' + c; d = (d - c) * 10; @@ -626,7 +624,7 @@ void mycvt(double d, char *buf) { if (*buf == '.') buf--; buf++; - + if (e != 1) { *buf++ = 'e'; itoa(e, buf); @@ -635,7 +633,6 @@ void mycvt(double d, char *buf) { } } - //% String toString(TValue v) { @@ -654,6 +651,11 @@ String toString(TValue v) { } else if (t == ValType::Number) { char buf[64]; + if (isNumber(v)) { + itoa(numValue(v), buf); + return mkString(buf); + } + double x = toDouble(v); if (isnan(x))