Class: EhbGameLib::Math::QuadraticEquation
- Inherits:
-
Object
- Object
- EhbGameLib::Math::QuadraticEquation
- Defined in:
- lib/ehb_game_lib/math/quadratic_equation.rb
Instance Attribute Summary collapse
-
#a ⇒ Object
readonly
Returns the value of attribute a.
-
#b ⇒ Object
readonly
Returns the value of attribute b.
-
#c ⇒ Object
readonly
Returns the value of attribute c.
Instance Method Summary collapse
- #delta ⇒ Object
-
#initialize(a, b, c) ⇒ QuadraticEquation
constructor
A new instance of QuadraticEquation.
- #root(signal) ⇒ Object
- #roots ⇒ Object
Constructor Details
#initialize(a, b, c) ⇒ QuadraticEquation
Returns a new instance of QuadraticEquation.
8 9 10 11 12 |
# File 'lib/ehb_game_lib/math/quadratic_equation.rb', line 8 def initialize(a, b, c) @a = a @b = b @c = c end |
Instance Attribute Details
#a ⇒ Object (readonly)
Returns the value of attribute a.
6 7 8 |
# File 'lib/ehb_game_lib/math/quadratic_equation.rb', line 6 def a @a end |
#b ⇒ Object (readonly)
Returns the value of attribute b.
6 7 8 |
# File 'lib/ehb_game_lib/math/quadratic_equation.rb', line 6 def b @b end |
#c ⇒ Object (readonly)
Returns the value of attribute c.
6 7 8 |
# File 'lib/ehb_game_lib/math/quadratic_equation.rb', line 6 def c @c end |
Instance Method Details
#delta ⇒ Object
21 22 23 |
# File 'lib/ehb_game_lib/math/quadratic_equation.rb', line 21 def delta @delta ||= b**2 - 4 * a * c end |
#root(signal) ⇒ Object
25 26 27 28 |
# File 'lib/ehb_game_lib/math/quadratic_equation.rb', line 25 def root(signal) signal = signal.negative? ? -1 : 1 (-b + signal * ::Math.sqrt(delta)) / (2 * a) end |