Convert int-to-string directly, without double, see #999 (#1009)

This commit is contained in:
Michał Moskal 2018-07-31 14:41:31 -07:00 committed by GitHub
parent 0ff39eb989
commit b0eee4afe5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,10 +4,8 @@
using namespace std; using namespace std;
#define p10(v) __builtin_powi(10, v) #define p10(v) __builtin_powi(10, v)
namespace pxt { namespace pxt {
static HandlerBinding *handlerBindings; static HandlerBinding *handlerBindings;
@ -610,7 +608,7 @@ void mycvt(double d, char *buf) {
int sig = 0; int sig = 0;
while (sig < 17 || beforeDot > 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; int c = (int)d;
*buf++ = '0' + c; *buf++ = '0' + c;
d = (d - c) * 10; d = (d - c) * 10;
@ -626,7 +624,7 @@ void mycvt(double d, char *buf) {
if (*buf == '.') if (*buf == '.')
buf--; buf--;
buf++; buf++;
if (e != 1) { if (e != 1) {
*buf++ = 'e'; *buf++ = 'e';
itoa(e, buf); itoa(e, buf);
@ -635,7 +633,6 @@ void mycvt(double d, char *buf) {
} }
} }
//% //%
String toString(TValue v) { String toString(TValue v) {
@ -654,6 +651,11 @@ String toString(TValue v) {
} else if (t == ValType::Number) { } else if (t == ValType::Number) {
char buf[64]; char buf[64];
if (isNumber(v)) {
itoa(numValue(v), buf);
return mkString(buf);
}
double x = toDouble(v); double x = toDouble(v);
if (isnan(x)) if (isnan(x))