Changeset 70615 in webkit


Ignore:
Timestamp:
Oct 26, 2010 10:42:29 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

2010-10-26 Dai Mikurube <dmikurube@google.com>

Reviewed by Kent Tamura.

constraint validation: stepMismatch (rounding error)
https://bugs.webkit.org/show_bug.cgi?id=48220

  • fast/forms/ValidityState-stepMismatch-expected.txt:
  • fast/forms/script-tests/ValidityState-stepMismatch.js:

2010-10-26 Dai Mikurube <dmikurube@google.com>

Reviewed by Kent Tamura.

constraint validation: stepMismatch (rounding error)
https://bugs.webkit.org/show_bug.cgi?id=48220

  1. Changed the computation to achieve difference from a integral multiple of the allowed value step.

The previous fmod(doubleValue, step) sometimes returned unacceptable
remainder. For example,

double doubleValue = 1.005; Actually, near to 1.005
double step = 0.005;
Actually, near to 0.005
fmod(doubleValue, step) ==> (near to) 0.005

It's a case that doubleValue is a little smaller than 1.005 and step is
a little larger than 0.005.

  1. Changed the error threshold.

Number values in HTML5 are expressed in IEEE 754 single-precision.
Too precise comparison sometimes leads unintended errors.

For example, I found a case :

remainder = 0.00000000000000022204460

acceptableError = 0.00000000000000007105427

  • html/NumberInputType.cpp: (WebCore::NumberInputType::stepMismatch):
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r70609 r70615  
     12010-10-26  Dai Mikurube  <dmikurube@google.com>
     2
     3        Reviewed by Kent Tamura.
     4
     5        constraint validation: stepMismatch (rounding error)
     6        https://bugs.webkit.org/show_bug.cgi?id=48220
     7
     8        * fast/forms/ValidityState-stepMismatch-expected.txt:
     9        * fast/forms/script-tests/ValidityState-stepMismatch.js:
     10
    1112010-10-26  Antonio Gomes  <agomes@rim.com>
    212
  • trunk/LayoutTests/fast/forms/ValidityState-stepMismatch-expected.txt

    r70549 r70615  
    143143PASS stepMismatchFor("0.9", "0.1000000000000001", "") is false
    144144PASS stepMismatchFor("1.0", "0.3333333333333333", "") is false
     145Rounding
     146PASS stepMismatchFor("5.005", "0.005", "4") is false
    145147
    146148Range type
  • trunk/LayoutTests/fast/forms/script-tests/ValidityState-stepMismatch.js

    r70549 r70615  
    160160shouldBe('stepMismatchFor("0.9", "0.1000000000000001", "")', 'false');
    161161shouldBe('stepMismatchFor("1.0", "0.3333333333333333", "")', 'false');
     162debug('Rounding');
     163shouldBe('stepMismatchFor("5.005", "0.005", "4")', 'false');
    162164
    163165debug('');
  • trunk/WebCore/ChangeLog

    r70605 r70615  
     12010-10-26  Dai Mikurube  <dmikurube@google.com>
     2
     3        Reviewed by Kent Tamura.
     4
     5        constraint validation: stepMismatch (rounding error)
     6        https://bugs.webkit.org/show_bug.cgi?id=48220
     7
     8        1. Changed the computation to achieve difference from a integral
     9        multiple of the allowed value step.
     10
     11        The previous fmod(doubleValue, step) sometimes returned unacceptable
     12        remainder. For example,
     13            double doubleValue = 1.005; // Actually, near to 1.005
     14            double step = 0.005; // Actually, near to 0.005
     15            fmod(doubleValue, step) ==> (near to) 0.005
     16        It's a case that doubleValue is a little smaller than 1.005 and step is
     17        a little larger than 0.005.
     18
     19        2. Changed the error threshold.
     20
     21        Number values in HTML5 are expressed in IEEE 754 single-precision.
     22        Too precise comparison sometimes leads unintended errors.
     23
     24        For example, I found a case :
     25                  remainder = 0.00000000000000022204460
     26            acceptableError = 0.00000000000000007105427
     27
     28        * html/NumberInputType.cpp:
     29        (WebCore::NumberInputType::stepMismatch):
     30
    1312010-10-26  Chris Rogers  <crogers@google.com>
    232
  • trunk/WebCore/html/NumberInputType.cpp

    r70549 r70615  
    122122        return false;
    123123    // double's fractional part size is DBL_MAN_DIG-bit. If the current value
    124     // is greater than step*2^DBL_MANT_DIG, the following fmod() makes no sense.
     124    // is greater than step*2^DBL_MANT_DIG, the following computation for
     125    // remainder makes no sense.
    125126    if (doubleValue / pow(2.0, DBL_MANT_DIG) > step)
    126127        return false;
    127     double remainder = fmod(doubleValue, step);
    128     // Accepts errors in lower 7-bit.
    129     double acceptableError = step / pow(2.0, DBL_MANT_DIG - 7);
     128    // The computation follows HTML5 4.10.7.2.10 `The step attribute' :
     129    // ... that number subtracted from the step base is not an integral multiple
     130    // of the allowed value step, the element is suffering from a step mismatch.
     131    double remainder = fabs(doubleValue - step * round(doubleValue / step));
     132    // Accepts erros in lower fractional part which IEEE 754 single-precision
     133    // can't represent.
     134    double acceptableError = step / pow(2.0, FLT_MANT_DIG);
    130135    return acceptableError < remainder && remainder < (step - acceptableError);
    131136}
Note: See TracChangeset for help on using the changeset viewer.