File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -64,25 +64,23 @@ struct gcd_traits_polynomial_defaults : public gcd_traits_defaults< boost::math:
6464 inline static void
6565 subtract (polynomial_type &a, polynomial_type const &b)
6666 {
67- // We want to use Stepanov's implementation as often as possible because
68- // it results in the smallest coefficients, however, whole numbers take
69- // precedence.
67+ // We use Stepanov's implementation when the constant coefficients
68+ // divide evenly, and Joux's otherwise.
7069 T m = constant_coefficient (a);
7170 gcd_traits<T>::modulo (m, constant_coefficient (b));
7271 if (!m)
7372 {
7473 T const r = constant_coefficient (a) / constant_coefficient (b);
75- // Stepanov's implementation; suffers from floating point inaccuracy
76- // when r does not divide ___ evenly.
7774 a -= r * b;
7875 }
7976 else
8077 {
81- // Antoine Joux's implementation: produces huge coefficients.
82- T const tmp = constant_coefficient (a);
83- a *= constant_coefficient (b);
84- a -= tmp * b;
85- normalize (a);
78+ // Antoine Joux's implementation tempered by coefficient gcd.
79+ T const a0 = constant_coefficient (a);
80+ T const b0 = constant_coefficient (b);
81+ T const gcd_a0b0 = gcd (a0, b0);
82+ a *= b0 / gcd_a0b0;
83+ a -= (a0 / gcd_a0b0) * b;
8684 }
8785 }
8886};
You can’t perform that action at this time.
0 commit comments