Commit f273a9fd authored by mjs's avatar mjs

Reviewed by Ken.

	- further corrections to number printing.

        * kjs/ustring.cpp:
        (UString::from): Make number printing match the ECMA standard
	algorithm.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@3053 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 1b19b279
2002-12-14 Maciej Stachowiak <mjs@apple.com>
Reviewed by Ken.
- further corrections to number printing.
* kjs/ustring.cpp:
(UString::from): Make number printing match the ECMA standard
algorithm.
2002-12-14 Maciej Stachowiak <mjs@apple.com>
Reviewed by Dave.
......
2002-12-14 Maciej Stachowiak <mjs@apple.com>
Reviewed by Ken.
- further corrections to number printing.
* kjs/ustring.cpp:
(UString::from): Make number printing match the ECMA standard
algorithm.
2002-12-14 Maciej Stachowiak <mjs@apple.com>
Reviewed by Dave.
......
......@@ -336,8 +336,8 @@ UString UString::from(double d)
char buf[80];
int decimalPoint;
int sign;
char *result = kjs_dtoa(d, 5, 16, &decimalPoint, &sign, NULL);
char *result = kjs_dtoa(d, 0, 0, &decimalPoint, &sign, NULL);
int length = strlen(result);
int i = 0;
......@@ -345,21 +345,55 @@ UString UString::from(double d)
buf[i++] = '-';
}
if (decimalPoint <= 0) {
if (decimalPoint <= 0 && decimalPoint > -6) {
buf[i++] = '0';
buf[i++] = '.';
for (int j = decimalPoint; j < 0; j++) {
buf[i++] = '0';
}
strcpy(buf + i, result);
} else if (decimalPoint >= length) {
} else if (decimalPoint <= 21 && decimalPoint > 0) {
if (length <= decimalPoint) {
strcpy(buf + i, result);
i += length;
for (int j = 0; j < decimalPoint - length; j++) {
buf[i++] = '0';
}
buf[i] = '\0';
} else {
strncpy(buf + i, result, decimalPoint);
i += decimalPoint;
buf[i++] = '.';
strcpy(buf + i, result + decimalPoint);
}
} else if (result[0] < '0' || result[0] > '9') {
strcpy(buf + i, result);
} else {
strncpy(buf + i, result, decimalPoint);
i += decimalPoint;
buf[i++] = '.';
strcpy(buf + i, result + decimalPoint);
buf[i++] = result[0];
if (length > 1) {
buf[i++] = '.';
strcpy(buf + i, result + 1);
i += length - 1;
}
buf[i++] = 'e';
buf[i++] = (decimalPoint >= 0) ? '+' : '-';
// decimalPoint can't be more than 3 digits decimal given the
// nature of float representation
int exponential = decimalPoint - 1;
if (exponential < 0) {
exponential = exponential * -1;
}
if (exponential >= 100) {
buf[i++] = '0' + exponential / 100;
}
if (exponential >= 10) {
buf[i++] = '0' + (exponential % 100) / 10;
}
buf[i++] = '0' + exponential % 10;
buf[i++] = '\0';
}
kjs_freedtoa(result);
return UString(buf);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment