aimstil  5.0.5
poly_solver.h
Go to the documentation of this file.
1 #ifndef POLYSOLVER_H_
2 #define POLYSOLVER_H_
3 
4 
5 namespace til { namespace math {
6 
7 
8  namespace policy { class InfinitySolutions_None; }
9 
10 
11  //---------------------------------------------------------------------------
12 
13  //-------------------//
14  // PolySolver_real //
15  //-------------------//
16 
21  template < typename TPrec, typename TInfinitySolutionsPolicy >
23  {
24  public: // constructors -----------------------------------------------------
25 
26  PolySolver_real() : m_infSolPolicy() {};
27 
28  public: // friends ----------------------------------------------------------
29 
30  // unfortunately, one cannot have a template parameter as a friend...
31  // TODO: This stuff has to be resolved, because obvisoulsy I don't want
32  // to add a friend to this class everytime a new policy is designed.
33  friend class policy::InfinitySolutions_None;
34 
35  public: // set & get --------------------------------------------------------
36 
38  int nsols() const { return m_nSols; }
40  const TPrec * sols() const { return m_sols; }
42  TInfinitySolutionsPolicy getInfSolPolicy() const { return m_infSolPolicy; }
43 
44  public: // functions --------------------------------------------------------
45 
47  void solve(TPrec a, TPrec b);
48 
50  void solve(TPrec a, TPrec b, TPrec c);
51 
52  private: // set & get -------------------------------------------------------
53 
54  void set_nsols(int n) { m_nSols = n; }
55  TPrec * get_sols() { return m_sols; }
56 
57  private: // data ------------------------------------------------------------
58  // number of solutions
59  // NB: we don't use std::vector because the solver has to be as fast as possible, AND the maximum size
60  // of the array is known and very small.
61  int m_nSols;
62  // solutions
63  // Well, we can't solve polynomial equations with a degree higher than 5, so a max of 5 solution will do.
64  TPrec m_sols[5];
65  // policy for infinity of solutions
66  TInfinitySolutionsPolicy m_infSolPolicy;
67  };
68 
69  //---------------------------------------------------------------------------
70 
71 
72 
73 }} // namespace til::math
74 
75 // package include
76 #include "poly_solver.tpp"
77 #include "poly_solver_policies.h"
78 
79 #endif /*POLYSOLVER_H_*/
const TPrec * sols() const
Return an array containing the solutions.
Definition: poly_solver.h:40
Belongs to package Box Do not include directly, include til/Box.h instead.
Definition: Accumulator.h:10
int nsols() const
Return the number of solutions.
Definition: poly_solver.h:38
Find real roots of a polynomial.
Definition: poly_solver.h:22
If the polynomial has an infinity of solutions, ignore all of them.
TInfinitySolutionsPolicy getInfSolPolicy() const
Return the "infinity of solutions" policy.
Definition: poly_solver.h:42