Use grisu2 algorithm for locale independent dtoa. Use BSD strtod.

This commit is contained in:
Tor Andersson
2017-05-22 14:48:23 +02:00
parent 5f83cc9842
commit bfebb7aa5c
3 changed files with 612 additions and 786 deletions

1390
jsdtoa.c

File diff suppressed because it is too large Load Diff

2
jsi.h
View File

@@ -87,7 +87,7 @@ void jsS_freestrings(js_State *J);
/* Portable strtod and printf float formatting */
void js_fmtexp(char *p, int e);
void js_dtoa(double f, char *digits, int *exp, int *neg, int *ndigits);
int js_grisu2(double v, char *buffer, int *K);
double js_strtod(const char *as, char **aas);
/* Private stack functions */

View File

@@ -220,16 +220,16 @@ double jsV_tointeger(js_State *J, js_Value *v)
const char *jsV_numbertostring(js_State *J, char buf[32], double f)
{
char digits[32], *p = buf, *s = digits;
int exp, neg, ndigits, point;
int exp, ndigits, point;
if (isnan(f)) return "NaN";
if (isinf(f)) return f < 0 ? "-Infinity" : "Infinity";
if (f == 0) return "0";
js_dtoa(f, digits, &exp, &neg, &ndigits);
ndigits = js_grisu2(f, digits, &exp);
point = ndigits + exp;
if (neg)
if (signbit(f))
*p++ = '-';
if (point < -5 || point > 21) {