<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[175796] trunk/Source</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/175796">175796</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2014-11-09 16:21:56 -0800 (Sun, 09 Nov 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add a more correct way to compare floating point numbers and use it
https://bugs.webkit.org/show_bug.cgi?id=138527

Reviewed by Darin Adler.

Source/WebCore:

Use the new WTF::areEssentuallyEqual() utility function from MathExtras.h
to compare floating-point numbers.

No new tests, no behavior change.

* page/DOMTimer.cpp:
(WebCore::DOMTimer::updateTimerIntervalIfNecessary):
* platform/graphics/FloatQuad.cpp:
(WebCore::FloatQuad::isRectilinear):
* platform/graphics/FloatRoundedRect.cpp:
(WebCore::FloatRoundedRect::Radii::isUniformCornerRadius):
* platform/graphics/FloatSize.h:
(WebCore::areEssentiallyEqual):
(WebCore::withinEpsilon): Deleted.

Source/WebKit/mac:

Use the new WTF::areEssentuallyEqual() utility function from MathExtras.h
to compare floating-point numbers.

* WebView/WebHTMLView.mm:
(-[WebHTMLView _adjustedBottomOfPageWithTop:bottom:limit:]):

Source/WebKit2:

Use the new WTF::areEssentuallyEqual() utility function from MathExtras.h
to compare floating-point numbers.

* UIProcess/API/Cocoa/WKWebView.mm:
(withinEpsilon):
* UIProcess/CoordinatedGraphics/PageViewportController.cpp:
(WebKit::PageViewportController::updateMinimumScaleToFit):
(WebKit::fuzzyCompare): Deleted.
* UIProcess/CoordinatedGraphics/PageViewportController.h:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::withinEpsilon):

* UIProcess/API/Cocoa/WKWebView.mm:
(areEssentiallyEqualAsFloat):
(-[WKWebView _didCommitLayerTree:]):
(withinEpsilon): Deleted.
* UIProcess/CoordinatedGraphics/PageViewportController.cpp:
(WebKit::PageViewportController::updateMinimumScaleToFit):
(WebKit::fuzzyCompare): Deleted.
* UIProcess/CoordinatedGraphics/PageViewportController.h:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::areEssentialEqualAsFloat):
(WebKit::WebPage::dynamicViewportSizeUpdate):
(WebKit::withinEpsilon): Deleted.

Source/WTF:

To compare floating point numbers in the code base, we would often rely
on the following check:
std::abs(a - b) &lt;= std::numeric_limits&lt;T&gt;::epsilon()

However, this is not correct for arbitrary floating point values, and
will fail for values that are not close to zero.

This patch introduces a WTF::areEssentiallyEqual() templated function
that can only be called with floating point types and relies on the
following formula from [1][2] that defines u as being &quot;essentially
equal&quot; to v if: | u - v | / |u| &lt;= e and | u - v | / |v| &lt;= e

[1] Knuth, D. E. &quot;Accuracy of Floating Point Arithmetic.&quot; The Art of
    Computer Programming. 3rd ed. Vol. 2. Boston: Addison-Wesley, 1998.
    229-45.
[2] http://www.boost.org/doc/libs/1_34_0/libs/test/doc/components/test_tools/floating_point_comparison.html

* wtf/MathExtras.h:
(WTF::safeFPDivision):
(WTF::areEssentiallyEqual):
(WTF::withinEpsilon): Deleted.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFwtfMathExtrash">trunk/Source/WTF/wtf/MathExtras.h</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorepageDOMTimercpp">trunk/Source/WebCore/page/DOMTimer.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsFloatQuadcpp">trunk/Source/WebCore/platform/graphics/FloatQuad.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsFloatRoundedRectcpp">trunk/Source/WebCore/platform/graphics/FloatRoundedRect.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsFloatSizeh">trunk/Source/WebCore/platform/graphics/FloatSize.h</a></li>
<li><a href="#trunkSourceWebKitmacChangeLog">trunk/Source/WebKit/mac/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitmacWebViewWebHTMLViewmm">trunk/Source/WebKit/mac/WebView/WebHTMLView.mm</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoaWKWebViewmm">trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessCoordinatedGraphicsPageViewportControllercpp">trunk/Source/WebKit2/UIProcess/CoordinatedGraphics/PageViewportController.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessCoordinatedGraphicsPageViewportControllerh">trunk/Source/WebKit2/UIProcess/CoordinatedGraphics/PageViewportController.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageiosWebPageIOSmm">trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (175795 => 175796)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog        2014-11-09 19:46:24 UTC (rev 175795)
+++ trunk/Source/WTF/ChangeLog        2014-11-10 00:21:56 UTC (rev 175796)
</span><span class="lines">@@ -1,3 +1,32 @@
</span><ins>+2014-11-09  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        Add a more correct way to compare floating point numbers and use it
+        https://bugs.webkit.org/show_bug.cgi?id=138527
+
+        Reviewed by Darin Adler.
+
+        To compare floating point numbers in the code base, we would often rely
+        on the following check:
+        std::abs(a - b) &lt;= std::numeric_limits&lt;T&gt;::epsilon()
+
+        However, this is not correct for arbitrary floating point values, and
+        will fail for values that are not close to zero.
+
+        This patch introduces a WTF::areEssentiallyEqual() templated function
+        that can only be called with floating point types and relies on the
+        following formula from [1][2] that defines u as being &quot;essentially
+        equal&quot; to v if: | u - v | / |u| &lt;= e and | u - v | / |v| &lt;= e
+
+        [1] Knuth, D. E. &quot;Accuracy of Floating Point Arithmetic.&quot; The Art of
+            Computer Programming. 3rd ed. Vol. 2. Boston: Addison-Wesley, 1998.
+            229-45.
+        [2] http://www.boost.org/doc/libs/1_34_0/libs/test/doc/components/test_tools/floating_point_comparison.html
+
+        * wtf/MathExtras.h:
+        (WTF::safeFPDivision):
+        (WTF::areEssentiallyEqual):
+        (WTF::withinEpsilon): Deleted.
+
</ins><span class="cx"> 2014-11-08  Darin Adler  &lt;darin@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Replace FileThread class with a single function
</span></span></pre></div>
<a id="trunkSourceWTFwtfMathExtrash"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/MathExtras.h (175795 => 175796)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/MathExtras.h        2014-11-09 19:46:24 UTC (rev 175795)
+++ trunk/Source/WTF/wtf/MathExtras.h        2014-11-10 00:21:56 UTC (rev 175796)
</span><span class="lines">@@ -393,11 +393,32 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> template &lt;typename T&gt;
</span><del>-inline bool withinEpsilon(T a, T b)
</del><ins>+inline typename std::enable_if&lt;std::is_floating_point&lt;T&gt;::value, T&gt;::type safeFPDivision(T u, T v)
</ins><span class="cx"> {
</span><del>-    return std::abs(a - b) &lt;= std::numeric_limits&lt;T&gt;::epsilon();
</del><ins>+    // Protect against overflow / underflow.
+    if (v &lt; 1 &amp;&amp; u &gt; v * std::numeric_limits&lt;T&gt;::max())
+        return std::numeric_limits&lt;T&gt;::max();
+    if (v &gt; 1 &amp;&amp; u &lt; v * std::numeric_limits&lt;T&gt;::min())
+        return 0;
+    return u / v;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+// Floating point numbers comparison:
+// u is &quot;essentially equal&quot; [1][2] to v if: | u - v | / |u| &lt;= e and | u - v | / |v| &lt;= e
+//
+// [1] Knuth, D. E. &quot;Accuracy of Floating Point Arithmetic.&quot; The Art of Computer Programming. 3rd ed. Vol. 2.
+//     Boston: Addison-Wesley, 1998. 229-45.
+// [2] http://www.boost.org/doc/libs/1_34_0/libs/test/doc/components/test_tools/floating_point_comparison.html
+template &lt;typename T&gt;
+inline typename std::enable_if&lt;std::is_floating_point&lt;T&gt;::value, bool&gt;::type areEssentiallyEqual(T u, T v, T epsilon = std::numeric_limits&lt;T&gt;::epsilon())
+{
+    if (u == v)
+        return true;
+
+    const T delta = std::abs(u - v);
+    return safeFPDivision(delta, std::abs(u)) &lt;= epsilon &amp;&amp; safeFPDivision(delta, std::abs(v)) &lt;= epsilon;
+}
+
</ins><span class="cx"> } // namespace WTF
</span><span class="cx"> 
</span><span class="cx"> #endif // #ifndef WTF_MathExtras_h
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (175795 => 175796)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-11-09 19:46:24 UTC (rev 175795)
+++ trunk/Source/WebCore/ChangeLog        2014-11-10 00:21:56 UTC (rev 175796)
</span><span class="lines">@@ -1,3 +1,25 @@
</span><ins>+2014-11-09  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        Add a more correct way to compare floating point numbers and use it
+        https://bugs.webkit.org/show_bug.cgi?id=138527
+
+        Reviewed by Darin Adler.
+
+        Use the new WTF::areEssentuallyEqual() utility function from MathExtras.h
+        to compare floating-point numbers.
+
+        No new tests, no behavior change.
+
+        * page/DOMTimer.cpp:
+        (WebCore::DOMTimer::updateTimerIntervalIfNecessary):
+        * platform/graphics/FloatQuad.cpp:
+        (WebCore::FloatQuad::isRectilinear):
+        * platform/graphics/FloatRoundedRect.cpp:
+        (WebCore::FloatRoundedRect::Radii::isUniformCornerRadius):
+        * platform/graphics/FloatSize.h:
+        (WebCore::areEssentiallyEqual):
+        (WebCore::withinEpsilon): Deleted.
+
</ins><span class="cx"> 2014-11-08  Simon Fraser  &lt;simon.fraser@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Implement round-rect clipping on video elements
</span></span></pre></div>
<a id="trunkSourceWebCorepageDOMTimercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/DOMTimer.cpp (175795 => 175796)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/DOMTimer.cpp        2014-11-09 19:46:24 UTC (rev 175795)
+++ trunk/Source/WebCore/page/DOMTimer.cpp        2014-11-10 00:21:56 UTC (rev 175796)
</span><span class="lines">@@ -270,11 +270,11 @@
</span><span class="cx">     double previousInterval = m_currentTimerInterval;
</span><span class="cx">     m_currentTimerInterval = intervalClampedToMinimum();
</span><span class="cx"> 
</span><del>-    if (WTF::withinEpsilon(previousInterval, m_currentTimerInterval))
</del><ins>+    if (WTF::areEssentiallyEqual(previousInterval, m_currentTimerInterval))
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     if (repeatInterval()) {
</span><del>-        ASSERT(WTF::withinEpsilon(repeatInterval(), previousInterval));
</del><ins>+        ASSERT(WTF::areEssentiallyEqual(repeatInterval(), previousInterval));
</ins><span class="cx">         augmentRepeatInterval(m_currentTimerInterval - previousInterval);
</span><span class="cx">     } else
</span><span class="cx">         augmentFireInterval(m_currentTimerInterval - previousInterval);
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsFloatQuadcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/FloatQuad.cpp (175795 => 175796)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/FloatQuad.cpp        2014-11-09 19:46:24 UTC (rev 175795)
+++ trunk/Source/WebCore/platform/graphics/FloatQuad.cpp        2014-11-10 00:21:56 UTC (rev 175796)
</span><span class="lines">@@ -93,8 +93,8 @@
</span><span class="cx"> 
</span><span class="cx"> bool FloatQuad::isRectilinear() const
</span><span class="cx"> {
</span><del>-    return (WTF::withinEpsilon(m_p1.x(), m_p2.x()) &amp;&amp; WTF::withinEpsilon(m_p2.y(), m_p3.y()) &amp;&amp; WTF::withinEpsilon(m_p3.x(), m_p4.x()) &amp;&amp; WTF::withinEpsilon(m_p4.y(), m_p1.y()))
-        || (WTF::withinEpsilon(m_p1.y(), m_p2.y()) &amp;&amp; WTF::withinEpsilon(m_p2.x(), m_p3.x()) &amp;&amp; WTF::withinEpsilon(m_p3.y(), m_p4.y()) &amp;&amp; WTF::withinEpsilon(m_p4.x(), m_p1.x()));
</del><ins>+    return (WTF::areEssentiallyEqual(m_p1.x(), m_p2.x()) &amp;&amp; WTF::areEssentiallyEqual(m_p2.y(), m_p3.y()) &amp;&amp; WTF::areEssentiallyEqual(m_p3.x(), m_p4.x()) &amp;&amp; WTF::areEssentiallyEqual(m_p4.y(), m_p1.y()))
+        || (WTF::areEssentiallyEqual(m_p1.y(), m_p2.y()) &amp;&amp; WTF::areEssentiallyEqual(m_p2.x(), m_p3.x()) &amp;&amp; WTF::areEssentiallyEqual(m_p3.y(), m_p4.y()) &amp;&amp; WTF::areEssentiallyEqual(m_p4.x(), m_p1.x()));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool FloatQuad::containsPoint(const FloatPoint&amp; p) const
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsFloatRoundedRectcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/FloatRoundedRect.cpp (175795 => 175796)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/FloatRoundedRect.cpp        2014-11-09 19:46:24 UTC (rev 175795)
+++ trunk/Source/WebCore/platform/graphics/FloatRoundedRect.cpp        2014-11-10 00:21:56 UTC (rev 175796)
</span><span class="lines">@@ -64,10 +64,10 @@
</span><span class="cx"> 
</span><span class="cx"> bool FloatRoundedRect::Radii::isUniformCornerRadius() const
</span><span class="cx"> {
</span><del>-    return WTF::withinEpsilon(m_topLeft.width(), m_topLeft.height())
-        &amp;&amp; withinEpsilon(m_topLeft, m_topRight)
-        &amp;&amp; withinEpsilon(m_topLeft, m_bottomLeft)
-        &amp;&amp; withinEpsilon(m_topLeft, m_bottomRight);
</del><ins>+    return WTF::areEssentiallyEqual(m_topLeft.width(), m_topLeft.height())
+        &amp;&amp; areEssentiallyEqual(m_topLeft, m_topRight)
+        &amp;&amp; areEssentiallyEqual(m_topLeft, m_bottomLeft)
+        &amp;&amp; areEssentiallyEqual(m_topLeft, m_bottomRight);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void FloatRoundedRect::Radii::scale(float factor)
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsFloatSizeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/FloatSize.h (175795 => 175796)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/FloatSize.h        2014-11-09 19:46:24 UTC (rev 175795)
+++ trunk/Source/WebCore/platform/graphics/FloatSize.h        2014-11-10 00:21:56 UTC (rev 175796)
</span><span class="lines">@@ -168,9 +168,9 @@
</span><span class="cx">     return a.width() == b.width() &amp;&amp; a.height() == b.height();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-inline bool withinEpsilon(const FloatSize&amp; a, const FloatSize&amp; b)
</del><ins>+inline bool areEssentiallyEqual(const FloatSize&amp; a, const FloatSize&amp; b)
</ins><span class="cx"> {
</span><del>-    return WTF::withinEpsilon(a.width(), b.width()) &amp;&amp; WTF::withinEpsilon(a.height(), b.height());
</del><ins>+    return WTF::areEssentiallyEqual(a.width(), b.width()) &amp;&amp; WTF::areEssentiallyEqual(a.height(), b.height());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> inline bool operator!=(const FloatSize&amp; a, const FloatSize&amp; b)
</span></span></pre></div>
<a id="trunkSourceWebKitmacChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/ChangeLog (175795 => 175796)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/ChangeLog        2014-11-09 19:46:24 UTC (rev 175795)
+++ trunk/Source/WebKit/mac/ChangeLog        2014-11-10 00:21:56 UTC (rev 175796)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2014-11-09  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        Add a more correct way to compare floating point numbers and use it
+        https://bugs.webkit.org/show_bug.cgi?id=138527
+
+        Reviewed by Darin Adler.
+
+        Use the new WTF::areEssentuallyEqual() utility function from MathExtras.h
+        to compare floating-point numbers.
+
+        * WebView/WebHTMLView.mm:
+        (-[WebHTMLView _adjustedBottomOfPageWithTop:bottom:limit:]):
+
</ins><span class="cx"> 2014-11-08  Alexey Proskuryakov  &lt;ap@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Delete cookies between tests
</span></span></pre></div>
<a id="trunkSourceWebKitmacWebViewWebHTMLViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/WebView/WebHTMLView.mm (175795 => 175796)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/WebView/WebHTMLView.mm        2014-11-09 19:46:24 UTC (rev 175795)
+++ trunk/Source/WebKit/mac/WebView/WebHTMLView.mm        2014-11-10 00:21:56 UTC (rev 175796)
</span><span class="lines">@@ -126,6 +126,7 @@
</span><span class="cx"> #import &lt;limits&gt;
</span><span class="cx"> #import &lt;runtime/InitializeThreading.h&gt;
</span><span class="cx"> #import &lt;wtf/MainThread.h&gt;
</span><ins>+#import &lt;wtf/MathExtras.h&gt;
</ins><span class="cx"> #import &lt;wtf/ObjcRuntimeExtras.h&gt;
</span><span class="cx"> #import &lt;wtf/RunLoop.h&gt;
</span><span class="cx"> 
</span><span class="lines">@@ -2412,7 +2413,7 @@
</span><span class="cx"> #ifdef __LP64__
</span><span class="cx">     // If the new bottom is equal to the old bottom (when both are treated as floats), we just return the original
</span><span class="cx">     // bottom. This prevents rounding errors that can occur when converting newBottom to a double.
</span><del>-    if (fabs(static_cast&lt;float&gt;(bottom) - newBottom) &lt;= std::numeric_limits&lt;float&gt;::epsilon()) 
</del><ins>+    if (WTF::areEssentiallyEqual(static_cast&lt;float&gt;(bottom), newBottom))
</ins><span class="cx">         return bottom;
</span><span class="cx">     else
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (175795 => 175796)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-11-09 19:46:24 UTC (rev 175795)
+++ trunk/Source/WebKit2/ChangeLog        2014-11-10 00:21:56 UTC (rev 175796)
</span><span class="lines">@@ -1,3 +1,35 @@
</span><ins>+2014-11-09  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        Add a more correct way to compare floating point numbers and use it
+        https://bugs.webkit.org/show_bug.cgi?id=138527
+
+        Reviewed by Darin Adler.
+
+        Use the new WTF::areEssentuallyEqual() utility function from MathExtras.h
+        to compare floating-point numbers.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (withinEpsilon):
+        * UIProcess/CoordinatedGraphics/PageViewportController.cpp:
+        (WebKit::PageViewportController::updateMinimumScaleToFit):
+        (WebKit::fuzzyCompare): Deleted.
+        * UIProcess/CoordinatedGraphics/PageViewportController.h:
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::withinEpsilon):
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (areEssentiallyEqualAsFloat):
+        (-[WKWebView _didCommitLayerTree:]):
+        (withinEpsilon): Deleted.
+        * UIProcess/CoordinatedGraphics/PageViewportController.cpp:
+        (WebKit::PageViewportController::updateMinimumScaleToFit):
+        (WebKit::fuzzyCompare): Deleted.
+        * UIProcess/CoordinatedGraphics/PageViewportController.h:
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::areEssentialEqualAsFloat):
+        (WebKit::WebPage::dynamicViewportSizeUpdate):
+        (WebKit::withinEpsilon): Deleted.
+
</ins><span class="cx"> 2014-11-08  Simon Fraser  &lt;simon.fraser@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Implement round-rect clipping on video elements
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoaWKWebViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (175795 => 175796)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm        2014-11-09 19:46:24 UTC (rev 175795)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm        2014-11-10 00:21:56 UTC (rev 175796)
</span><span class="lines">@@ -75,6 +75,7 @@
</span><span class="cx"> #import &lt;JavaScriptCore/JSContext.h&gt;
</span><span class="cx"> #import &lt;JavaScriptCore/JSValue.h&gt;
</span><span class="cx"> #import &lt;wtf/HashMap.h&gt;
</span><ins>+#import &lt;wtf/MathExtras.h&gt;
</ins><span class="cx"> #import &lt;wtf/NeverDestroyed.h&gt;
</span><span class="cx"> #import &lt;wtf/RetainPtr.h&gt;
</span><span class="cx"> 
</span><span class="lines">@@ -829,10 +830,9 @@
</span><span class="cx"> 
</span><span class="cx"> // WebCore stores the page scale factor as float instead of double. When we get a scale from WebCore,
</span><span class="cx"> // we need to ignore differences that are within a small rounding error on floats.
</span><del>-template &lt;typename TypeA, typename TypeB&gt;
-static inline bool withinEpsilon(TypeA a, TypeB b)
</del><ins>+static inline bool areEssentiallyEqualAsFloat(float a, float b)
</ins><span class="cx"> {
</span><del>-    return std::abs(a - b) &lt; std::numeric_limits&lt;float&gt;::epsilon();
</del><ins>+    return WTF::areEssentiallyEqual(a, b);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (void)_didCommitLayerTree:(const WebKit::RemoteLayerTreeTransaction&amp;)layerTreeTransaction
</span><span class="lines">@@ -882,7 +882,7 @@
</span><span class="cx">     if (_needsToRestoreExposedRect &amp;&amp; layerTreeTransaction.transactionID() &gt;= _firstTransactionIDAfterPageRestore) {
</span><span class="cx">         _needsToRestoreExposedRect = NO;
</span><span class="cx"> 
</span><del>-        if (withinEpsilon(contentZoomScale(self), _scaleToRestore)) {
</del><ins>+        if (areEssentiallyEqualAsFloat(contentZoomScale(self), _scaleToRestore)) {
</ins><span class="cx">             WebCore::FloatPoint exposedPosition = _exposedRectToRestore.location();
</span><span class="cx">             exposedPosition.scale(_scaleToRestore, _scaleToRestore);
</span><span class="cx"> 
</span><span class="lines">@@ -894,7 +894,7 @@
</span><span class="cx">     if (_needsToRestoreUnobscuredCenter &amp;&amp; layerTreeTransaction.transactionID() &gt;= _firstTransactionIDAfterPageRestore) {
</span><span class="cx">         _needsToRestoreUnobscuredCenter = NO;
</span><span class="cx"> 
</span><del>-        if (withinEpsilon(contentZoomScale(self), _scaleToRestore)) {
</del><ins>+        if (areEssentiallyEqualAsFloat(contentZoomScale(self), _scaleToRestore)) {
</ins><span class="cx">             CGRect unobscuredRect = UIEdgeInsetsInsetRect(self.bounds, _obscuredInsets);
</span><span class="cx">             WebCore::FloatSize unobscuredContentSizeAtNewScale(unobscuredRect.size.width / _scaleToRestore, unobscuredRect.size.height / _scaleToRestore);
</span><span class="cx">             WebCore::FloatPoint topLeftInDocumentCoordinate(_unobscuredCenterToRestore.x() - unobscuredContentSizeAtNewScale.width() / 2, _unobscuredCenterToRestore.y() - unobscuredContentSizeAtNewScale.height() / 2);
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessCoordinatedGraphicsPageViewportControllercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/CoordinatedGraphics/PageViewportController.cpp (175795 => 175796)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/CoordinatedGraphics/PageViewportController.cpp        2014-11-09 19:46:24 UTC (rev 175795)
+++ trunk/Source/WebKit2/UIProcess/CoordinatedGraphics/PageViewportController.cpp        2014-11-10 00:21:56 UTC (rev 175796)
</span><span class="lines">@@ -33,11 +33,6 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><del>-bool fuzzyCompare(float a, float b, float epsilon)
-{
-    return std::abs(a - b) &lt; epsilon;
-}
-
</del><span class="cx"> PageViewportController::PageViewportController(WebKit::WebPageProxy* proxy, PageViewportControllerClient&amp; client)
</span><span class="cx">     : m_webPageProxy(proxy)
</span><span class="cx">     , m_client(client)
</span><span class="lines">@@ -327,14 +322,16 @@
</span><span class="cx">     if (m_viewportSize.isEmpty() || m_contentsSize.isEmpty())
</span><span class="cx">         return false;
</span><span class="cx"> 
</span><del>-    bool currentlyScaledToFit = fuzzyCompare(m_pageScaleFactor, m_minimumScaleToFit, 0.0001);
</del><ins>+    // FIXME: Why this arbitrary precision? We likely want to omit the third argument so that
+    // std::numeric_limits&lt;float&gt;::epsilon() is used instead, similarly to Mac / iOS.
+    bool currentlyScaledToFit = WTF::areEssentiallyEqual(m_pageScaleFactor, m_minimumScaleToFit, 0.0001f);
</ins><span class="cx"> 
</span><span class="cx">     float minimumScale = WebCore::computeMinimumScaleFactorForContentContained(m_rawAttributes, WebCore::roundedIntSize(m_viewportSize), WebCore::roundedIntSize(m_contentsSize));
</span><span class="cx"> 
</span><span class="cx">     if (minimumScale &lt;= 0)
</span><span class="cx">         return false;
</span><span class="cx"> 
</span><del>-    if (!fuzzyCompare(minimumScale, m_minimumScaleToFit, 0.0001)) {
</del><ins>+    if (!WTF::areEssentiallyEqual(minimumScale, m_minimumScaleToFit, 0.0001f)) {
</ins><span class="cx">         m_minimumScaleToFit = minimumScale;
</span><span class="cx"> 
</span><span class="cx">         if (!m_webPageProxy-&gt;areActiveDOMObjectsAndAnimationsSuspended()) {
</span><span class="lines">@@ -343,7 +340,7 @@
</span><span class="cx">             else {
</span><span class="cx">                 // Ensure the effective scale stays within bounds.
</span><span class="cx">                 float boundedScale = innerBoundedViewportScale(m_pageScaleFactor);
</span><del>-                if (!fuzzyCompare(boundedScale, m_pageScaleFactor, 0.0001))
</del><ins>+                if (!WTF::areEssentiallyEqual(boundedScale, m_pageScaleFactor, 0.0001f))
</ins><span class="cx">                     applyScaleAfterRenderingContents(boundedScale);
</span><span class="cx">             }
</span><span class="cx">         }
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessCoordinatedGraphicsPageViewportControllerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/CoordinatedGraphics/PageViewportController.h (175795 => 175796)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/CoordinatedGraphics/PageViewportController.h        2014-11-09 19:46:24 UTC (rev 175795)
+++ trunk/Source/WebKit2/UIProcess/CoordinatedGraphics/PageViewportController.h        2014-11-10 00:21:56 UTC (rev 175796)
</span><span class="lines">@@ -108,8 +108,6 @@
</span><span class="cx">     WebCore::FloatRect m_lastFrameCoveredRect;
</span><span class="cx"> };
</span><span class="cx"> 
</span><del>-bool fuzzyCompare(float, float, float epsilon);
-
</del><span class="cx"> } // namespace WebKit
</span><span class="cx"> 
</span><span class="cx"> #endif // PageViewportController_h
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageiosWebPageIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm (175795 => 175796)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm        2014-11-09 19:46:24 UTC (rev 175795)
+++ trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm        2014-11-10 00:21:56 UTC (rev 175796)
</span><span class="lines">@@ -87,6 +87,7 @@
</span><span class="cx"> #import &lt;WebCore/VisibleUnits.h&gt;
</span><span class="cx"> #import &lt;WebCore/WKContentObservation.h&gt;
</span><span class="cx"> #import &lt;WebCore/WebEvent.h&gt;
</span><ins>+#import &lt;wtf/MathExtras.h&gt;
</ins><span class="cx"> #import &lt;wtf/TemporaryChange.h&gt;
</span><span class="cx"> 
</span><span class="cx"> using namespace WebCore;
</span><span class="lines">@@ -2211,9 +2212,11 @@
</span><span class="cx">     m_page-&gt;mainFrame().orientationChanged();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static inline bool withinEpsilon(float a, float b)
</del><ins>+// WebCore stores the page scale factor as float instead of double. When we get a scale from WebCore,
+// we need to ignore differences that are within a small rounding error on floats.
+static inline bool areEssentialEqualAsFloat(float a, float b)
</ins><span class="cx"> {
</span><del>-    return fabs(a - b) &lt; std::numeric_limits&lt;float&gt;::epsilon();
</del><ins>+    return WTF::areEssentiallyEqual(a, b);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebPage::resetTextAutosizingBeforeLayoutIfNeeded(const FloatSize&amp; oldSize, const FloatSize&amp; newSize)
</span><span class="lines">@@ -2282,7 +2285,7 @@
</span><span class="cx">     FloatRect newUnobscuredContentRect = targetUnobscuredRect;
</span><span class="cx">     FloatRect newExposedContentRect = targetExposedContentRect;
</span><span class="cx"> 
</span><del>-    bool scaleChanged = !withinEpsilon(scale, targetScale);
</del><ins>+    bool scaleChanged = !areEssentialEqualAsFloat(scale, targetScale);
</ins><span class="cx">     if (scaleChanged) {
</span><span class="cx">         // The target scale the UI is using cannot be reached by the content. We need to compute new targets based
</span><span class="cx">         // on the viewport constraint and report everything back to the UIProcess.
</span><span class="lines">@@ -2347,7 +2350,7 @@
</span><span class="cx">                 newExposedContentRect.setY(0);
</span><span class="cx">             }
</span><span class="cx"> 
</span><del>-            bool likelyResponsiveDesignViewport = newLayoutSize.width() == minimumLayoutSize.width() &amp;&amp; withinEpsilon(scale, 1);
</del><ins>+            bool likelyResponsiveDesignViewport = newLayoutSize.width() == minimumLayoutSize.width() &amp;&amp; areEssentialEqualAsFloat(scale, 1);
</ins><span class="cx">             bool contentBleedsOutsideLayoutWidth = newContentSize.width() &gt; newLayoutSize.width();
</span><span class="cx">             bool originalScrollPositionWasOnTheLeftEdge = targetUnobscuredRect.x() &lt;= 0;
</span><span class="cx">             if (likelyResponsiveDesignViewport &amp;&amp; contentBleedsOutsideLayoutWidth &amp;&amp; originalScrollPositionWasOnTheLeftEdge) {
</span></span></pre>
</div>
</div>

</body>
</html>