Skip to content

Commit

Permalink
fix: Fixed the case when the root of a quadratic equation can be any …
Browse files Browse the repository at this point in the history
…natural number
  • Loading branch information
cheatsnake committed Jul 31, 2022
1 parent c4654c8 commit b25c3b2
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/math/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ func GetQuadratic(minA, maxA, minB, maxB, minC, maxC int) QuadraticEquation {
x1 := (-float64(b) - (math.Sqrt(float64(discriminant)))) / (2 * float64(a))
x2 := (-float64(b) + (math.Sqrt(float64(discriminant)))) / (2 * float64(a))

// The case when the root can be any natural number
if math.IsNaN(x1) {
return QuadraticEquation{equation, a, b, c, discriminant, "R", "R"}
}

return QuadraticEquation{
equation, a, b, c, discriminant,
strconv.FormatFloat(x1, 'f', 3, 64),
Expand Down

0 comments on commit b25c3b2

Please sign in to comment.