quadratic-roots
Compute the real roots of a quadratic equation in a numerically stable manner
Introduction
In floating point arithmetic, the naive method for determining the roots of a quadratic equation ("x equals negative b, plus or minus etc.") may lead to severe cancellation and an inaccurate result.
Sample usage:
var roots = // --> [] // --> [] // --> [-3] // --> [-4,3] // --> [2,2] // --> []
Install
$ npm install quadratic-roots
API
require('quadratic-roots')( a, b, c )
Compute the roots of the polynomial ax^2 + bx + c = 0.
Returns
- If no roots, returns an empty array
[]
- If a linear equation, returns one root
- If a parabola with no real roots, returns an empty array
- If a parabola with one root multiplicity 2, returns an array with the same root twice
- Otherwise returns an array with two real roots
Credits
(c) 2015 Ricky Reusser. MIT License