a little help with my program?

Terry Reedy tjreedy at udel.edu
Tue Apr 3 13:40:47 EDT 2001


> import math
...
> x.real = -(b) + pow(b**2 - 4(a)(c)) / 2

If the discriminant (b**2-4.0*a*c)/2 is >=0, you can replace pow with
math.sqrt.
If negative, you must use cmath.sqrt.

However, for serious quadratic root finding, the above formula is NOT the
one to use for actual computation.  A fairly standard alternative is given
in many numerical analysis books, with explanation.






More information about the Python-list mailing list