Skip to content

Commit a1433a9

Browse files
Added test cases
1 parent 685469d commit a1433a9

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

math/quadratic_equations_complex_numbers.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,20 @@ std::array<std::complex<long double>, 2> quadraticEquation(long double a,
5252
long double discriminant = b * b - 4 * a * c;
5353
std::array<std::complex<long double>, 2> solutions{0, 0};
5454

55-
// Complex root (discriminant < 0)
56-
// Note that the left term (-b / 2a) is always real. The imaginary part
57-
// appears when b^2 - 4ac < 0, so sqrt(b^2 - 4ac) has no real roots. So, the
58-
// imaginary component is i * (+/-)sqrt(abs(b^2 - 4ac)) / 2a.
55+
/// Complex root (discriminant < 0)
56+
/// Note that the left term (-b / 2a) is always real. The imaginary part
57+
/// appears when b^2 - 4ac < 0, so sqrt(b^2 - 4ac) has no real roots. So,
58+
/// the imaginary component is i * (+/-)sqrt(abs(b^2 - 4ac)) / 2a.
5959
if (discriminant < 0) {
60-
// Since b^2 - 4ac is < 0, for faster computation, -discriminant is
61-
// enough to make it positive.
60+
/// Since b^2 - 4ac is < 0, for faster computation, -discriminant is
61+
/// enough to make it positive.
6262
solutions[0] = std::complex<long double>{
6363
-b * 0.5 / a, -std::sqrt(-discriminant) * 0.5 / a};
6464
solutions[1] = std::complex<long double>{
6565
-b * 0.5 / a, std::sqrt(-discriminant) * 0.5 / a};
6666
} else {
67-
// Since discriminant > 0, there are only real roots. Therefore,
68-
// imaginary component = 0.
67+
/// Since discriminant > 0, there are only real roots. Therefore,
68+
/// imaginary component = 0.
6969
solutions[0] = std::complex<long double>{
7070
(-b - std::sqrt(discriminant)) * 0.5 / a, 0};
7171
solutions[1] = std::complex<long double>{

0 commit comments

Comments
 (0)