Line data Source code
1 1 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : /// \file 5 : /// Declares functions for solving quadratic equations 6 : 7 : #pragma once 8 : 9 : #include <array> 10 : 11 : /*! 12 : * \ingroup NumericalAlgorithmsGroup 13 : * \brief Returns the positive root of a quadratic equation \f$ax^2 + 14 : * bx + c = 0\f$ 15 : * \returns The positive root of a quadratic equation. 16 : * \requires That there are two real roots, of which only one is positive. 17 : */ 18 1 : double positive_root(double a, double b, double c); 19 : 20 : /*! 21 : * \ingroup NumericalAlgorithmsGroup 22 : * \brief Returns the smallest root of a quadratic equation \f$ax^2 + 23 : * bx + c = 0\f$ that is greater than the given value, within roundoff. 24 : * \returns A root of a quadratic equation. 25 : * \requires That there are two real roots. 26 : * \requires At least one root is greater than the given value, to roundoff. 27 : */ 28 : template <typename T> 29 1 : T smallest_root_greater_than_value_within_roundoff(const T& a, const T& b, 30 : const T& c, double value); 31 : /*! 32 : * \ingroup NumericalAlgorithmsGroup 33 : * \brief Returns the largest root of a quadratic equation 34 : * \f$ax^2 + bx + c = 0\f$ that is between min_value and max_value, 35 : * within roundoff. 36 : * \returns A root of a quadratic equation. 37 : * \requires That there are two real roots. 38 : * \requires At least one root is between min_value and max_value, to roundoff. 39 : */ 40 : template <typename T> 41 1 : T largest_root_between_values_within_roundoff(const T& a, const T& b, 42 : const T& c, double min_value, 43 : double max_value); 44 : /*! 45 : * \ingroup NumericalAlgorithmsGroup 46 : * \brief Returns the two real roots of a quadratic equation \f$ax^2 + 47 : * bx + c = 0\f$ with the root closer to \f$-\infty\f$ first. 48 : * \returns An array of the roots of a quadratic equation 49 : * \requires That there are two real roots. 50 : */ 51 1 : std::array<double, 2> real_roots(double a, double b, double c);