Terry J. Reedy added the comment:

To include corner cases, I should have asked 'at least as accurate' rather than 
'more accurate'.  It would be a sad libm that had specialized functions worse 
than pow, since the specialized functions could, at worse, use pow.

For an expert point of view, the reason for math to have the specialized 
functions is to give access to functions in the libm of the compiler used. A 
beginner ignorant of such things might wonder whether exp and sqrt are just 
trivial abbreviations, and if not, which to use.  I believe this question has 
appeared on python-list.  It definitely has on StackOverflow.

For e**x, there is, for instance,
https://stackoverflow.com/questions/30756983/difference-between-math-exp2-and-math-e2
with this comment "Voting to reopen. There's more going on here than simply 
"floating-point is inaccurate". In particular, as the two answers explain, 
there are good reasons to expect exp(x) to be more accurate than e**x. – Mark 
Dickinson " ;-).

Searching "[python] math.sqrt pow" gets more hits.
https://stackoverflow.com/questions/18965524/exponentiation-in-python-should-i-prefer-operator-instead-of-math-pow-and-m
https://stackoverflow.com/questions/33684948/difference-between-1-2-math-sqrt-and-cmath-sqrt
and multiple questions about relative speed.

So I am inclined to add "This is generally better than math.e ** x and 
math.pow(e, 0.5)." (for math.exp) and "than x ** 0.5 and math.pow(x, 0.5)" for 
math.sqrt, and similarly for cmath.sqrt).

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue29956>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to