Changeset 2912 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
Dec 3, 2002, 2:51:39 PM (22 years ago)
Author:
mjs
Message:
  • fixed 3114790 - Gamespot reviews pages badly mis-rendering because floating point numbers format wide

Reviewed by: David Hyatt

  • kjs/dtoa.cpp: Imported float <--> string conversion routines from David M. Gay. I changed this to fix warnings and avoid colliding with names of standard library functions.
  • kjs/dtoa.h: Added a header I made up for dtoa.cpp
  • kjs/ustring.cpp: (UString::from): Use new double to string routine (kjs_strtod). (UString::toDouble): Use new string to double routine (kjs_dtoa).
  • JavaScriptCore.pbproj/project.pbxproj: Added new files
Location:
trunk/JavaScriptCore/kjs
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/ustring.cpp

    r2846 r2912  
    3939#include "identifier.h"
    4040#include <math.h>
     41#include "dtoa.h"
    4142
    4243namespace KJS {
     
    333334UString UString::from(double d)
    334335{
    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 
    355362  return UString(buf);
    356363}
     
    507514    // regular number ?
    508515    char *end;
    509     d = strtod(c, &end);
     516    d = kjs_strtod(c, &end);
    510517    if ((d != 0.0 || end != c) && d != HUGE_VAL && d != -HUGE_VAL) {
    511518      c = end;
Note: See TracChangeset for help on using the changeset viewer.