Re: math.nroot [was Re: A brief question.]



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?
.



Relevant Pages

  • Re: Coding inside the debugger
    ... but why isn't the test written so that the reason it fails is ... If something fails in tests like these, ... public void testCreateWithDefaultthrows Exception { ... Ghostworld world = worldWithClass; ...
    (comp.object)
  • Re: I need help please!
    ... It is documented on some systems I've use a lot as a standard way of exiting at any point. ... Any software written for general consumption should deal with unexpected keystrokes for the simple reason that, in the real world, they are very common. ... So you "REASONABLE man's method" fails on a very common system, ... I would say that a "solution" that does not work on a very common platform is NOT a reasonable solution. ...
    (comp.lang.c)
  • Re: what is wrong?
    ... The only reason you "should" get no output is if the int 21h/47h fails. ... After the "xlatb", ...
    (alt.lang.asm)
  • Re: split by word using | as delimiter
    ... Others have answered your primary question. ... comments; hope you don't mind. ... If 'open' fails, the reason is stored in the ...
    (comp.lang.perl.misc)
  • Re: CreateProcess not work on Vista
    ... Whenever you call an API function, and it fails, you MUST call ... and after the CreateProcess you must ReleaseBuffer ... ZeroMemory (&si, sizeof (si)); ... Without knowing the reason for the error, you have no idea why it failed. ...
    (microsoft.public.vc.mfc)