Math.pow() predates ** by many releases. On Sunday, October 21, 2012, Steven D'Aprano wrote:
> On 21/10/12 21:11, Antoine Pitrou wrote: > >> On Sun, 21 Oct 2012 13:38:48 +1100 >> Chris Angelico<ros...@gmail.com> wrote: >> >>> On Sun, Oct 21, 2012 at 12:53 PM, Steven D'Aprano<st...@pearwood.info> >>> wrote: >>> >>>> Python 2.x legitimately distinguished between floats and complex, e.g.: >>>> >>>> py> (-100.0)**0.5 >>>> >>>> Traceback (most recent call last): >>>> File "<stdin>", line 1, in<module> >>>> ValueError: negative number cannot be raised to a fractional power >>>> >>>> If you wanted a complex result, you can explicitly ask for one: >>>> >>>> py> (-100.0+0j)**0.5 >>>> (6.123031769111886e-16+10j) >>>> >>>> >>>> I see that behaviour is changed in Python 3. >>>> >>> >>> Python 2 (future directives aside) also required you to explicitly ask >>> for floating point. That was also changed in Python 3. That doesn't >>> mean that this is necessarily the right thing to do, but it does have >>> precedent. The square root of a negative number is by nature a complex >>> number. >>> >> >> In the set of complex numbers, it is. But in the set of float numbers, >> a negative number has no square root. I think Steven may be worried >> about the impact on people who don't know about complex numbers, which >> is a reasonable concern. >> > > Precisely. > > > I'm also not sure why we have several variants of the power operator: >> **, built-in pow(), math.pow(). >> > > In Python 3.3, math.pow is the builtin pow. Presumably for backwards > compatibility reasons when they were different? If so, it was a LONG > time ago: > > [steve@ando ~]$ python1.5 > Python 1.5.2 (#1, Aug 27 2012, 09:09:18) [GCC 4.1.2 20080704 (Red Hat > 4.1.2-52)] on linux2 > Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam > >> import math >>>> math.pow >>>> >>> <built-in function pow> > > > And yet strangely there's never been a cmath.pow. > > > > -- > Steven > ______________________________**_________________ > Python-Dev mailing list > Python-Dev@python.org > http://mail.python.org/**mailman/listinfo/python-dev<http://mail.python.org/mailman/listinfo/python-dev> > Unsubscribe: http://mail.python.org/**mailman/options/python-dev/** > guido%40python.org<http://mail.python.org/mailman/options/python-dev/guido%40python.org> > -- --Guido van Rossum (python.org/~guido)
_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com