Skip to content

Commit

Permalink
prevent taking the sqrt of a negative number
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Stephens committed Jul 17, 2015
1 parent c066fd2 commit 18979ea
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/laguerre.js
Expand Up @@ -10,10 +10,10 @@ Laguerre.solve = function solve(guess, fn, dfn, d2fn) {
var f = fn(x),
fPrime = dfn(x),
fPrimePrime = d2fn(x),
delta = 2 * Math.sqrt(
delta = 2 * Math.sqrt(Math.abs(
(4 * Math.pow(fPrime, 2)) -
(5 * f * fPrimePrime)
),
)),
dx = (5 * f) / (fPrime + ((Math.abs(fPrime) / fPrime) * delta));

x = x - dx;
Expand Down

0 comments on commit 18979ea

Please sign in to comment.