Spaces:
Sleeping
Sleeping
Update app.cpp
Browse files
app.cpp
CHANGED
|
@@ -33,9 +33,11 @@ CubicRoots solveCubic(double a, double b, double c, double d) {
|
|
| 33 |
const double epsilon = 1e-14;
|
| 34 |
const double zero_threshold = 1e-10; // Threshold for considering a value as zero
|
| 35 |
|
|
|
|
|
|
|
|
|
|
| 36 |
// Handle special case for a == 0 (quadratic)
|
| 37 |
if (std::abs(a) < epsilon) {
|
| 38 |
-
CubicRoots roots;
|
| 39 |
// For a quadratic equation: bz^2 + cz + d = 0
|
| 40 |
if (std::abs(b) < epsilon) { // Linear equation or constant
|
| 41 |
if (std::abs(c) < epsilon) { // Constant - no finite roots
|
|
@@ -72,7 +74,6 @@ CubicRoots solveCubic(double a, double b, double c, double d) {
|
|
| 72 |
// Handle special case when d is zero - one root is zero
|
| 73 |
if (std::abs(d) < epsilon) {
|
| 74 |
// Factor out z: z(az^2 + bz + c) = 0
|
| 75 |
-
CubicRoots roots;
|
| 76 |
roots.root1 = std::complex<double>(0.0, 0.0); // One root is exactly zero
|
| 77 |
|
| 78 |
// Solve the quadratic: az^2 + bz + c = 0
|
|
|
|
| 33 |
const double epsilon = 1e-14;
|
| 34 |
const double zero_threshold = 1e-10; // Threshold for considering a value as zero
|
| 35 |
|
| 36 |
+
// Declare roots at the beginning of the function so it's in scope throughout
|
| 37 |
+
CubicRoots roots;
|
| 38 |
+
|
| 39 |
// Handle special case for a == 0 (quadratic)
|
| 40 |
if (std::abs(a) < epsilon) {
|
|
|
|
| 41 |
// For a quadratic equation: bz^2 + cz + d = 0
|
| 42 |
if (std::abs(b) < epsilon) { // Linear equation or constant
|
| 43 |
if (std::abs(c) < epsilon) { // Constant - no finite roots
|
|
|
|
| 74 |
// Handle special case when d is zero - one root is zero
|
| 75 |
if (std::abs(d) < epsilon) {
|
| 76 |
// Factor out z: z(az^2 + bz + c) = 0
|
|
|
|
| 77 |
roots.root1 = std::complex<double>(0.0, 0.0); // One root is exactly zero
|
| 78 |
|
| 79 |
// Solve the quadratic: az^2 + bz + c = 0
|