diff options
author | Bernd Weimer <bweimer@blackberry.com> | 2013-07-18 14:32:20 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-07-29 19:29:15 +0200 |
commit | cebac1ae2f09abaca12cb6a052dd2043d09e0ae5 (patch) | |
tree | db4a01d886bc0bc024b64974deff15f472a6fca6 /src/corelib/tools/qeasingcurve.cpp | |
parent | 4237faf5800a9af41962d45b9297d3464adc30e2 (diff) |
Avoided zero devision in cube root approximation
Halley's method to get a better approximation is omitted, if it
would include a devision by zero (INFINITY/NaN is worse).
Change-Id: Ida09326e2b5892d7cb21bcb956631c289e5b56ba
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qeasingcurve.cpp')
-rw-r--r-- | src/corelib/tools/qeasingcurve.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/corelib/tools/qeasingcurve.cpp b/src/corelib/tools/qeasingcurve.cpp index bc0a14ea72..67e0711796 100644 --- a/src/corelib/tools/qeasingcurve.cpp +++ b/src/corelib/tools/qeasingcurve.cpp @@ -608,14 +608,16 @@ struct BezierEase : public QEasingCurveFunction sign = -1; d = d * sign; - qreal t_i = _fast_cbrt(d); + qreal t = _fast_cbrt(d); //one step of Halley's Method to get a better approximation - const qreal t_i_cubic = t_i * t_i * t_i; - qreal t = t_i * (t_i_cubic + d + d) / (t_i_cubic + t_i_cubic + d); + const qreal t_cubic = t * t * t; + const qreal f = t_cubic + t_cubic + d; + if (f != qreal(0.0)) + t = t * (t_cubic + d + d) / f; //another step - /*t_i = t; + /*qreal t_i = t; t_i_cubic = pow(t_i, 3); t = t_i * (t_i_cubic + d + d) / (t_i_cubic + t_i_cubic + d);*/ |