On 2023-02-18 03:52:51 +0000, Oscar Benjamin wrote: > On Sat, 18 Feb 2023 at 01:47, Chris Angelico <ros...@gmail.com> wrote: > > On Sat, 18 Feb 2023 at 12:41, Greg Ewing via Python-list > > > To avoid it you would need to use an algorithm that computes nth > > > roots directly rather than raising to the power 1/n. > > > > > > > It's somewhat curious that we don't really have that. We have many > > other inverse operations - addition and subtraction (not just "negate > > and add"), multiplication and division, log and exp - but we have > > exponentiation without an arbitrary-root operation. For square roots, > > that's not a problem, since we can precisely express the concept > > "raise to the 0.5th power", but for anything else, we have to raise to > > a fractional power that might be imprecise. > > Various libraries can do this. Both SymPy and NumPy have cbrt for cube roots:
Yes, but that's a special case. Chris was talking about arbitrary (integer) roots. My calculator has a button labelled [x√y], but my processor doesn't have an equivalent operation. Come to think of it, it doesn't even have a a y**x operation - just some simpler operations which can be used to implement it. GCC doesn't inline pow(y, x) on x86/64 - it just calls the library function. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | h...@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!"
signature.asc
Description: PGP signature
-- https://mail.python.org/mailman/listinfo/python-list