Created
April 17, 2020 17:31
-
-
Save Tythos/075b9ede16ea69cfd55f9c61fa2058a4 to your computer and use it in GitHub Desktop.
Useful collection of numerical methods with no dependencies; mostly bare for now, with great plans for the future, let me tell you :D
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Useful collection of numerical methods | |
*/ | |
define(function(require, exports, module) { | |
function quadratic(a, b, c) { | |
/* Returns a two-element Array of root solutions to the quadratic | |
defined by the coefficients a, b, and c. Depending on the solution, | |
one or both elements may be NaN. | |
*/ | |
let b2 = Math.pow(b, 2); | |
let det = Math.pow(b2 - 4 * a * c, 0.5); | |
let x1 = (-b + det) / (2 * a); | |
let x2 = (-b - det) / (2 * a); | |
if (x1 == x2) { | |
x2 = NaN; | |
} | |
return [x1, x2]; | |
} | |
return { | |
quadratic: quadratic | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment