17 #ifndef GZ_MATH_POLYNOMIAL3_HH_
18 #define GZ_MATH_POLYNOMIAL3_HH_
28 #include <gz/math/config.hh>
33 inline namespace GZ_MATH_VERSION_NAMESPACE {
50 : coeffs(
std::move(_coeffs))
82 if (abs(this->coeffs[0]) >= epsilon)
84 return _x * copysign(T(1.), this->coeffs[0]);
86 if (abs(this->coeffs[1]) >= epsilon)
88 return copysign(_x, this->coeffs[1]);
90 if (abs(this->coeffs[2]) >= epsilon)
92 return _x * copysign(T(1.), this->coeffs[2]);
94 return this->coeffs[3];
96 const T _x2 = _x * _x;
97 const T _x3 = _x2 * _x;
99 return (this->coeffs[0] * _x3 + this->coeffs[1] * _x2 +
100 this->coeffs[2] * _x + this->coeffs[3]);
107 return this->Evaluate(_x);
118 if (_interval.
Empty())
127 const T yLeft = this->Evaluate(xLeft);
128 const T yRight = this->Evaluate(xRight);
141 if (abs(this->coeffs[0]) >= epsilon)
148 const T a = this->coeffs[0] * T(3.);
149 const T b = this->coeffs[1] * T(2.);
150 const T c = this->coeffs[2];
152 const T discriminant = b * b - T(4.) * a * c;
153 if (discriminant >= T(0.))
156 const T x = (-b + sqrt(discriminant)) / (T(2.) * a);
159 const T y = this->Evaluate(x);
168 else if (abs(this->coeffs[1]) >= epsilon)
172 const T a = this->coeffs[1];
173 const T b = this->coeffs[2];
176 const T x = -b / (T(2.) * a);
179 const T y = this->Evaluate(x);
198 return this->Minimum(_interval, xMin);
222 constexpr T epsilon =
224 bool streamStarted =
false;
225 for (
size_t i = 0; i < 4; ++i)
228 const T magnitude = abs(this->coeffs[i]);
229 const bool sign = this->coeffs[i] < T(0);
230 const int exponent = 3 -
static_cast<int>(i);
231 if (magnitude >= epsilon)
250 if ((magnitude - T(1)) > epsilon)
252 _out << magnitude <<
" ";
257 _out <<
"^" << exponent;
264 streamStarted =
true;
269 _out << this->coeffs[3];