mirror of
https://github.com/ccxvii/mujs.git
synced 2026-02-06 09:51:41 +08:00
Use grisu2 algorithm for locale independent dtoa. Use BSD strtod.
This commit is contained in:
2
jsi.h
2
jsi.h
@@ -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 */
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user