2 ms·
How does one solve a quadratic in just two lines? Did you omit degenerate case checks and/or number of roots?
by wruza 4y ago
How does one solve a quadratic in just two lines? Did you omit degenerate case checks and/or number of roots?
- mojuba 4y agoNo. Depending on the language you can find a way of returning 0 to 2 results. Could be a dynamic array, could be a tuple that allows NaN's of some sort.
- aragilar 4y agoWhat algorithm did you use? The standard formula is pretty inaccurate, whereas following most of https://people.eecs.berkeley.edu/~wkahan/Math128/Cubic.pdf https://people.eecs.berkeley.edu/~wkahan/Math128/Cubic.pdf, I was able to get down to near machine precision. I've seen enough cases where someone blindly copied in a formula (or numerical algorithm) from a textbook, without considering how the numerics behave, and getting bad results, to trust unsourced numerical code.