Commit 7c33c6fe authored by mjs's avatar mjs

- 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


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@2912 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent c054e2c1
2002-12-03 Maciej Stachowiak <mjs@apple.com>
- 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
2002-11-27 John Sullivan <sullivan@apple.com>
* kjs/collector.cpp:
......
2002-12-03 Maciej Stachowiak <mjs@apple.com>
- 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
2002-11-27 John Sullivan <sullivan@apple.com>
* kjs/collector.cpp:
......
2002-12-03 Maciej Stachowiak <mjs@apple.com>
- 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
2002-11-27 John Sullivan <sullivan@apple.com>
* kjs/collector.cpp:
......
......@@ -227,6 +227,7 @@
9374D3A9038D9D74008635CE,
9373524F038DA8C2008635CE,
931C6CF1038EE8DE008635CE,
651F6415039D5B5F0078395C,
);
isa = PBXHeadersBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
......@@ -274,6 +275,7 @@
933A349E038AE80F008635CE,
9374D3AA038D9D74008635CE,
931C6CF2038EE8DE008635CE,
651F6414039D5B5F0078395C,
);
isa = PBXSourcesBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
......@@ -441,6 +443,40 @@
//102
//103
//104
//650
//651
//652
//653
//654
651F6412039D5B5F0078395C = {
fileEncoding = 30;
isa = PBXFileReference;
path = dtoa.cpp;
refType = 4;
};
651F6413039D5B5F0078395C = {
fileEncoding = 30;
isa = PBXFileReference;
path = dtoa.h;
refType = 4;
};
651F6414039D5B5F0078395C = {
fileRef = 651F6412039D5B5F0078395C;
isa = PBXBuildFile;
settings = {
};
};
651F6415039D5B5F0078395C = {
fileRef = 651F6413039D5B5F0078395C;
isa = PBXBuildFile;
settings = {
};
};
//650
//651
//652
//653
//654
//930
//931
//932
......@@ -710,6 +746,8 @@
F692A8670255597D01FF60F7,
F68EBB8C0255D4C601FF60F7,
F5C290E60284F98E018635CA,
651F6412039D5B5F0078395C,
651F6413039D5B5F0078395C,
);
isa = PBXGroup;
name = "Other Sources";
......
This diff is collapsed.
// -*- c-basic-offset: 2 -*-
/*
* This file is part of the KDE libraries
* Copyright (C) 2002 Apple Computer, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
#ifndef _KJS_DTOA_H_
#define _KJS_DTOA_H_
extern "C" double kjs_strtod(const char *s00, char **se);
extern "C" char *kjs_dtoa(double d, int mode, int ndigits,
int *decpt, int *sign, char **rve);
extern "C" void kjs_freedtoa(char *s);
#endif /* _KJS_DTOA_H */
......@@ -38,6 +38,7 @@
#include "operations.h"
#include "identifier.h"
#include <math.h>
#include "dtoa.h"
namespace KJS {
extern const double NaN;
......@@ -332,26 +333,32 @@ UString UString::from(long l)
UString UString::from(double d)
{
char buf[40];
char buf[80];
int decimalPoint;
int sign;
if (d == -0)
strcpy(buf,"0");
else if (KJS::isNaN(d))
strcpy(buf,"NaN");
else if (KJS::isPosInf(d))
strcpy(buf,"Infinity");
else if (KJS::isNegInf(d))
strcpy(buf,"-Infinity");
else
sprintf(buf, "%.16g", d); // does the right thing
// ECMA 3rd ed. 9.8.1 9 e: "with no leading zeros"
int buflen = strlen(buf);
if (buflen >= 4 && buf[buflen-4] == 'e' && buf[buflen-2] == '0') {
buf[buflen-2] = buf[buflen-1];
buf[buflen-1] = 0;
char *result = kjs_dtoa(d, 5, 16, &decimalPoint, &sign, NULL);
int length = strlen(result);
int i = 0;
if (sign) {
buf[i++] = '-';
}
if (decimalPoint <= 0) {
buf[i++] = 0;
buf[i++] = '.';
strcpy(buf + i, result);
} else if (decimalPoint >= length) {
strcpy(buf + i, result);
} else {
strncpy(buf + i, result, decimalPoint);
i += decimalPoint;
buf[i++] = '.';
strcpy(buf + i, result + decimalPoint);
}
kjs_freedtoa(result);
return UString(buf);
}
......@@ -506,7 +513,7 @@ double UString::toDouble( bool tolerant ) const
} else {
// regular number ?
char *end;
d = strtod(c, &end);
d = kjs_strtod(c, &end);
if ((d != 0.0 || end != c) && d != HUGE_VAL && d != -HUGE_VAL) {
c = end;
} else {
......
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