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) noexcept; 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, 31 : double value) noexcept; 32 : /*! 33 : * \ingroup NumericalAlgorithmsGroup 34 : * \brief Returns the largest root of a quadratic equation 35 : * \f$ax^2 + bx + c = 0\f$ that is between min_value and max_value, 36 : * within roundoff. 37 : * \returns A root of a quadratic equation. 38 : * \requires That there are two real roots. 39 : * \requires At least one root is between min_value and max_value, to roundoff. 40 : */ 41 : template <typename T> 42 1 : T largest_root_between_values_within_roundoff(const T& a, const T& b, 43 : const T& c, double min_value, 44 : double max_value) noexcept; 45 : /*! 46 : * \ingroup NumericalAlgorithmsGroup 47 : * \brief Returns the two real roots of a quadratic equation \f$ax^2 + 48 : * bx + c = 0\f$ with the root closer to \f$-\infty\f$ first. 49 : * \returns An array of the roots of a quadratic equation 50 : * \requires That there are two real roots. 51 : */ 52 1 : std::array<double, 2> real_roots(double a, double b, double c) noexcept;