Re: math.nroot [was Re: A brief question.]
- From: Tom Anderson <twic@xxxxxxxxxxxxxxx>
- Date: Sun, 3 Jul 2005 20:13:22 +0100
On Sun, 3 Jul 2005, George Sakkis wrote:
"Tom Anderson" <twic@xxxxxxxxxxxxxxx> wrote:
And finally, does Guido know something about arithmetic that i don't, or is this expression:
-1.0 ** 0.5
Evaluated wrongly?
No, it is evaluated according to the rules of precedence. It is equivalent to -(1.0**0.5). You are confusing it with (-1.0)**0.5 which fails as expected.
Ah. My mistake. I submit that this is also a bug in python's grammar. There's probably some terribly good reason for it, though.
How about 'conformance with standard mathematic notation', does this count for a terribly good reason?
Yes. However, it's an excellent reason why python's precedence rules are wrong - in conventional mathematical notation, the unary minus, used to denote the sign of a literal number, does indeed have higher precedence than exponentiation: -1^2 evaluates to 1, not -1.
What would one expect to be the result of 5^2 - 2^2, 29 or 21?
21.
Would you expect 5^2 + - 2^2 to be different, even if you write it as 5^2 + -2 ^ 2 ?
Yes: 5^2 + -2^2 is 29, however you write it.
White space is not significant in math AFAIK ;-)
No, but there's a very big difference between unary and binary minus.
tom
-- When you mentioned INSERT-MIND-INPUT ... did they look at you like this? .
- Follow-Ups:
- Re: math.nroot [was Re: A brief question.]
- From: OKB (not okblacke)
- Re: math.nroot [was Re: A brief question.]
- From: James Dennett
- Re: math.nroot [was Re: A brief question.]
- References:
- Re: A brief question.
- From: Tom Brown
- Re: A brief question.
- From: Tom Anderson
- Re: A brief question.
- From: Fredrik Johansson
- math.nroot [was Re: A brief question.]
- From: Steven D'Aprano
- Re: math.nroot [was Re: A brief question.]
- From: Tom Anderson
- Re: math.nroot [was Re: A brief question.]
- From: Steven D'Aprano
- Re: math.nroot [was Re: A brief question.]
- From: Tom Anderson
- Re: math.nroot [was Re: A brief question.]
- From: George Sakkis
- Re: A brief question.
- Prev by Date: Re: How do you program in Python?
- Next by Date: Re: Using regular expressions in internet searches
- Previous by thread: Re: math.nroot [was Re: A brief question.]
- Next by thread: Re: math.nroot [was Re: A brief question.]
- Index(es):
Relevant Pages
|