Quellcode durchsuchen

polynomial: accuracy improvement on double root in order 3

undefined
Guillaume Bittoun Sam Hocevar <sam@hocevar.net> vor 9 Jahren
Ursprung
Commit
3f6cd5b120
2 geänderte Dateien mit 2 neuen und 2 gelöschten Zeilen
  1. +1
    -1
      src/lol/math/polynomial.h
  2. +1
    -1
      src/t/math/polynomial.cpp

+ 1
- 1
src/lol/math/polynomial.h Datei anzeigen

@@ -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 Datei anzeigen

@@ -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);
}



Laden…
Abbrechen
Speichern