Browse Source

polynomial: accuracy improvement on double root in order 3

undefined
Guillaume Bittoun Sam Hocevar <sam@hocevar.net> 9 years ago
parent
commit
3f6cd5b120
2 changed files with 2 additions and 2 deletions
  1. +1
    -1
      src/lol/math/polynomial.h
  2. +1
    -1
      src/t/math/polynomial.cpp

+ 1
- 1
src/lol/math/polynomial.h View File

@@ -231,7 +231,7 @@ struct polynomial
// if root of the derivative is also root of the current polynomial, we have a double root.
for (auto root : polynomial<T>{c, T(2)*b, T(3)*a}.roots())
if (eval(root) == T(0))
return array<T> { solutions[0] - k,
return array<T> { (solutions[0] + solutions[2]) / T(2) - k,
solutions[1] - k };

// we have 3 or 1 root depending on delta sign


+ 1
- 1
src/t/math/polynomial.cpp View File

@@ -288,7 +288,7 @@ lolunit_declare_fixture(polynomial_test)

// Should have 2 solutions only, but precision leads to 3 solutions
lolunit_assert_equal(roots1.count(), 2);
lolunit_assert_doubles_equal(roots1[0], -1, 1e-3);
lolunit_assert_doubles_equal(roots1[0], -1, 1e-6);
lolunit_assert_doubles_equal(roots1[1], -2, 1e-6);
}



Loading…
Cancel
Save