in reply to solving a quadratic equation

In addittion to the two errors others have pointed out, note that the correct formula is

-($b + (0 < $b ? 1 : -1) * sqrt($b*$b - 4*$a * $c)) / 2*$a

Replies are listed 'Best First'.
Re^2: solving a quadratic equation
by SuicideJunkie (Vicar) on Dec 08, 2009 at 14:57 UTC

    Ambrus: Why does your choice of root depend on the sign of $b?

    Returning a list containing both roots is quite reasonable for Perl, and then the calling function can decide what subset of them it wants to use.
    I would also suggest a test for $a being too small, and then use a linear solution rather than trying to divide by zero.