X root Operator help

Michael Hoffman cam.ac.uk at mh391.invalid
Wed Apr 18 10:54:31 EDT 2007


[Michael Hoffman]
>> In floating point arithmetic, the naive way of calculating both roots
>> always using the formula (-b +/- sqrt(b**2 - 4*a*c))/2*a will give you
>> inaccurate results sometimes. See
>> <http://www.cse.uiuc.edu/eot/modules/floating_point/quadratic_formula/>.

[lucidparadox]
> Thanks.  As of right now I'm just trying to familiarize myself with
> the syntax of Python.  Actually I should have thought of y**(1/x).

math.sqrt(y) might be faster or even more accurate (depending on 
platform) than y**0.5.

> I'm currently a freshman in college so the alternative formula hasn't
> been introduced to me yet.

It probably won't be unless you take a class in numerical analysis. Many 
a person has been burned by not thinking about these sorts of things 
until it is too late (myself included).
-- 
Michael Hoffman



More information about the Python-list mailing list