-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEq2deg.hpp
83 lines (77 loc) · 2.11 KB
/
Eq2deg.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef __EQ2DEG_HPP
#define __EQ2DEG_HPP
/**
* CS-17, Eq2deg.hpp
* Base class to manage quadratics equations
* a*x^2+b*x+c=0
*
* with the following restrictions:
* The coefficients are real
* The roots are real
* In case of complex roots an exception is thrown
*
* @author Christophe Gattardi
* @version 1.0 15/03/2020
*/
// //////////////////////////////////////////////////////////////////////
// Import section
// //////////////////////////////////////////////////////////////////////
// STL
#include <vector>
#include <Utilities.hpp>
class Eq2deg: public Utilities{
protected:
double m_a, m_b, m_c;
double m_delta;
std::vector<double> m_rac;
public:
/**
* @brief Construct a new Eq2deg object
*
* @param a double: coefficent of x^2
* @param b double: coefficient of x
* @param c double: constant
*/
Eq2deg(const double& iA, const double& iB, const double& iC );
virtual ~Eq2deg();
/**
* @brief compute the discriminant and raise an exception if negative
*
*/
virtual void computeDelta();
/**
* @brief Compute the roots
*
*/
virtual void computeRoots();
/**
* @brief Get the root value by number
*
* @param rootNumber the number of the root to retrieve (1 or 2)
* @return double
*/
double getRoot(const int& iRootNumber) const;
/**
* @brief Get the discriminant
*
* @return double
*/
virtual double getDelta();
/**
* @brief Object to handle exception when no reals roots exists
*
*/
struct NegativeDeltaException : public std::exception {
const char * what () const throw () {
return "Invalid coefficients, no real roots";
}
};
private:
/**
* Display of the object.
*
* @return std::string Dump of the object.
*/
virtual std::string describe() const;
};
#endif //__EQ2DEG_HPP