On Numbers

Steven D'Aprano steve at REMOVETHIScyber.com.au
Wed Jan 18 12:44:00 CET 2006

On Tue, 17 Jan 2006 23:34:40 +0000, Tom Anderson wrote:


>>> So I don't really know what point you are making. What solution(s) for 
>>> 1**0.5 were you expecting?
>> He's probably getting at the fact that if you're dealing with complex 
>> numbers, square root get a lot more complicated:
>> 	http://mathworld.wolfram.com/SquareRoot.html
>> But still, that doesn't change the fact that x**0.5 as is meant here is 
>> the principal (positive) real square root, and that can be true whether 
>> your hierarchy of numeric types includes a complex type or not.
> Er, actually, i meant to write -1, but evidently missed a key, and failed 
> to check what i'd written.

Since exponentiation has higher priority than negation, -1**0.5 is -1.0 in
both Python and ordinary mathematics. 

Perhaps you meant to write (-1)**0.5, in which case Python developers have
a decision to make: should it assume real-valued maths unless explicitly
told differently, and hence raise an exception, or coerce the result to

In this case, Python raises an exception, as it should, unless you
explicitly uses complex numbers. That's the best behaviour for the
majority of people: most people don't even know what complex numbers are,
let alone want to deal with them in their code. Python, after all, is not


More information about the Python-list mailing list