summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools/qeasingcurve
diff options
context:
space:
mode:
authorBernd Weimer <bweimer@blackberry.com>2013-07-18 14:32:20 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-07-29 19:29:15 +0200
commitcebac1ae2f09abaca12cb6a052dd2043d09e0ae5 (patch)
treedb4a01d886bc0bc024b64974deff15f472a6fca6 /tests/auto/corelib/tools/qeasingcurve
parent4237faf5800a9af41962d45b9297d3464adc30e2 (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 'tests/auto/corelib/tools/qeasingcurve')
-rw-r--r--tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp b/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp
index fa747b3c18..3348b49110 100644
--- a/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp
+++ b/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp
@@ -730,14 +730,16 @@ double static inline _fast_cbrt(double d)
void tst_QEasingCurve::testCbrtDouble()
{
- const qreal errorBound = 0.0001;
+ const double errorBound = 0.0001;
for (int i = 0; i < 100000; i++) {
double d = double(i) / 1000.0;
double t = _fast_cbrt(d);
const double t_cubic = t * t * t;
- t = t * (t_cubic + d + d) / (t_cubic + t_cubic + d);
+ const double f = t_cubic + t_cubic + d;
+ if (f != 0.0)
+ t = t * (t_cubic + d + d) / f;
double expected = pow(d, 1.0/3.0);
@@ -754,14 +756,16 @@ void tst_QEasingCurve::testCbrtDouble()
void tst_QEasingCurve::testCbrtFloat()
{
- const qreal errorBound = 0.0005;
+ const float errorBound = 0.0005;
- for (int i = 1; i < 100000; i++) {
+ for (int i = 0; i < 100000; i++) {
float f = float(i) / 1000.0f;
float t = _fast_cbrt(f);
const float t_cubic = t * t * t;
- t = t * (t_cubic + f + f) / (t_cubic + t_cubic + f);
+ const float fac = t_cubic + t_cubic + f;
+ if (fac != 0.0f)
+ t = t * (t_cubic + f + f) / fac;
float expected = pow(f, float(1.0/3.0));