From 64f5b0cfdcbeacb4fe0aaf03810efa7572c858cc Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Wed, 7 Apr 2010 18:12:45 +0200 Subject: Updated JavaScriptCore from /home/khansen/dev/qtwebkit-qtscript-integration to javascriptcore-snapshot-07042010 ( da4f912a2f648d518628e1066dace894d1da7081 ) [Windows] Fix a bug of round() with huge integral numbers https://bugs.webkit.org/show_bug.cgi?id=34297 --- .../javascriptcore/JavaScriptCore/ChangeLog | 24 +++++++++++++++++++++ .../javascriptcore/JavaScriptCore/wtf/MathExtras.h | 25 ++++++++++++++++------ src/3rdparty/javascriptcore/VERSION | 2 +- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/src/3rdparty/javascriptcore/JavaScriptCore/ChangeLog b/src/3rdparty/javascriptcore/JavaScriptCore/ChangeLog index 68411ab..cfad1ea 100644 --- a/src/3rdparty/javascriptcore/JavaScriptCore/ChangeLog +++ b/src/3rdparty/javascriptcore/JavaScriptCore/ChangeLog @@ -1,3 +1,27 @@ +2010-01-31 Kent Tamura + + Reviewed by Darin Adler. + + [Windows] Fix a bug of round() with huge integral numbers + https://bugs.webkit.org/show_bug.cgi?id=34297 + + Fix a bug that round() for huge integral numbers returns incorrect + results. For example, round(8639999913600001) returns + 8639999913600002 without this change though the double type can + represent 8639999913600001 precisely. + + Math.round() of JavaScript has a similar problem. But this change + doesn't fix it because Math.round() doesn't use round() of + MathExtra.h. + + * wtf/MathExtras.h: + (round): Avoid to do "num + 0.5" or "num - 0.5". + (roundf): Fixed similarly. + (llround): Calls round(). + (llroundf): Calls roundf(). + (lround): Calls round(). + (lroundf): Calls roundf(). + 2010-01-27 Anton Muhin Reviewed by Darin Adler. diff --git a/src/3rdparty/javascriptcore/JavaScriptCore/wtf/MathExtras.h b/src/3rdparty/javascriptcore/JavaScriptCore/wtf/MathExtras.h index 9ea57fd..a18949e 100644 --- a/src/3rdparty/javascriptcore/JavaScriptCore/wtf/MathExtras.h +++ b/src/3rdparty/javascriptcore/JavaScriptCore/wtf/MathExtras.h @@ -98,12 +98,25 @@ inline bool signbit(double x) { struct ieee_double *p = (struct ieee_double *)&x #if COMPILER(MSVC) || COMPILER(RVCT) -inline long long llround(double num) { return static_cast(num > 0 ? num + 0.5 : ceil(num - 0.5)); } -inline long long llroundf(float num) { return static_cast(num > 0 ? num + 0.5f : ceil(num - 0.5f)); } -inline long lround(double num) { return static_cast(num > 0 ? num + 0.5 : ceil(num - 0.5)); } -inline long lroundf(float num) { return static_cast(num > 0 ? num + 0.5f : ceilf(num - 0.5f)); } -inline double round(double num) { return num > 0 ? floor(num + 0.5) : ceil(num - 0.5); } -inline float roundf(float num) { return num > 0 ? floorf(num + 0.5f) : ceilf(num - 0.5f); } +// We must not do 'num + 0.5' or 'num - 0.5' because they can cause precision loss. +static double round(double num) +{ + double integer = ceil(num); + if (num > 0) + return integer - num > 0.5 ? integer - 1.0 : integer; + return integer - num >= 0.5 ? integer - 1.0 : integer; +} +static float roundf(float num) +{ + float integer = ceilf(num); + if (num > 0) + return integer - num > 0.5f ? integer - 1.0f : integer; + return integer - num >= 0.5f ? integer - 1.0f : integer; +} +inline long long llround(double num) { return static_cast(round(num)); } +inline long long llroundf(float num) { return static_cast(roundf(num)); } +inline long lround(double num) { return static_cast(round(num)); } +inline long lroundf(float num) { return static_cast(roundf(num)); } inline double trunc(double num) { return num > 0 ? floor(num) : ceil(num); } #endif diff --git a/src/3rdparty/javascriptcore/VERSION b/src/3rdparty/javascriptcore/VERSION index 581837e..a96e22f 100644 --- a/src/3rdparty/javascriptcore/VERSION +++ b/src/3rdparty/javascriptcore/VERSION @@ -8,4 +8,4 @@ The commit imported was from the and has the sha1 checksum - 8662fcc9bb1d374fa10114fe629f18290641cccc + da4f912a2f648d518628e1066dace894d1da7081 -- cgit v0.12