Mark Dickinson <dicki...@gmail.com> added the comment:

> Perhaps because it is so easy to write x**(1/3), and if you want a real root 
> of negative argument, it is -(-x)**(1/3).

I consider `x**(1/3)` to be a trap and a bug magnet: many people won't realise 
that the correct spelling for their situation is actually `def f(x): return 
-((-x)**(1/3)) if x < 0 else x**(1/3)` and the failure mode of `x**(1/3)` for 
negative `x` seems suboptimal, in that it happily returns a complex number 
rather than raising a `ValueError` with a clear message indicating what was 
wrong. I've seen a good number of Stack Overflow questions from users confused 
about this exact thing.

And not only is that correct spelling unwieldy, but it _still_ doesn't do the 
right thing for `-0.0`, and if you care about getting that corner case right 
then the right spelling becomes even more unwieldy.

Of course, even with `math.cbrt` in the standard library people will still fall 
into the `x**(1/3)` trap, but at least we then have a decent replacement to 
point them to.

----------

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

Reply via email to