Changeset 2912 in webkit for trunk/JavaScriptCore/kjs/ustring.cpp
- Timestamp:
- Dec 3, 2002, 2:51:39 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/ustring.cpp
r2846 r2912 39 39 #include "identifier.h" 40 40 #include <math.h> 41 #include "dtoa.h" 41 42 42 43 namespace KJS { … … 333 334 UString UString::from(double d) 334 335 { 335 char buf[40]; 336 337 if (d == -0) 338 strcpy(buf,"0"); 339 else if (KJS::isNaN(d)) 340 strcpy(buf,"NaN"); 341 else if (KJS::isPosInf(d)) 342 strcpy(buf,"Infinity"); 343 else if (KJS::isNegInf(d)) 344 strcpy(buf,"-Infinity"); 345 else 346 sprintf(buf, "%.16g", d); // does the right thing 347 348 // ECMA 3rd ed. 9.8.1 9 e: "with no leading zeros" 349 int buflen = strlen(buf); 350 if (buflen >= 4 && buf[buflen-4] == 'e' && buf[buflen-2] == '0') { 351 buf[buflen-2] = buf[buflen-1]; 352 buf[buflen-1] = 0; 353 } 354 336 char buf[80]; 337 int decimalPoint; 338 int sign; 339 340 char *result = kjs_dtoa(d, 5, 16, &decimalPoint, &sign, NULL); 341 int length = strlen(result); 342 343 int i = 0; 344 if (sign) { 345 buf[i++] = '-'; 346 } 347 348 if (decimalPoint <= 0) { 349 buf[i++] = 0; 350 buf[i++] = '.'; 351 strcpy(buf + i, result); 352 } else if (decimalPoint >= length) { 353 strcpy(buf + i, result); 354 } else { 355 strncpy(buf + i, result, decimalPoint); 356 i += decimalPoint; 357 buf[i++] = '.'; 358 strcpy(buf + i, result + decimalPoint); 359 } 360 kjs_freedtoa(result); 361 355 362 return UString(buf); 356 363 } … … 507 514 // regular number ? 508 515 char *end; 509 d = strtod(c, &end);516 d = kjs_strtod(c, &end); 510 517 if ((d != 0.0 || end != c) && d != HUGE_VAL && d != -HUGE_VAL) { 511 518 c = end;
Note:
See TracChangeset
for help on using the changeset viewer.