This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients AjithRamachandran, lemburg, mark.dickinson, rhettinger, serhiy.storchaka, stutzbach
Date 2021-06-09.12:28:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1623241688.62.0.0589655577595.issue44357@roundup.psfhosted.org>
In-reply-to
Content
> 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.
History
Date User Action Args
2021-06-09 12:28:08mark.dickinsonsetrecipients: + mark.dickinson, lemburg, rhettinger, stutzbach, serhiy.storchaka, AjithRamachandran
2021-06-09 12:28:08mark.dickinsonsetmessageid: <1623241688.62.0.0589655577595.issue44357@roundup.psfhosted.org>
2021-06-09 12:28:08mark.dickinsonlinkissue44357 messages
2021-06-09 12:28:08mark.dickinsoncreate