3-arg float pow()

Tim Peters tim at zope.com
Tue Sep 4 20:50:02 CEST 2001


[Marcin 'Qrczak']
> I would expect pow to use multiplication when the exponent is an
> integer (with a signle division if it's negative),

As I said, that's less accurate than a decent libm pow() when floats are
involved, so is a bad idea in that case.

> and the libm pow or equivalently exp(b*ln(a)) if the exponent is a float.

Sorry, but a libm that implemented pow(x, y) literally as exp(b*ln(a))
couldn't be given away (it's numerically atrocious for large |ln(a)| and/or
large |b| -- decent fp math libraries are much harder to write than I expect
you're aware of).

> So (-3)**2 would be defined, but (-3)**2.0 would be not.

Current CVS Python handles both fine, and even a raw libm pow() should have
no problems with pow(-3, 2.0).

> And 3**(-2) should return a rational.

If we had rationals, sure.  In the meantime 0.1111111111111111 is better
than 0.





More information about the Python-list mailing list