Pergunta

As google suggests -10=-1. And as I understand pow() function in javascript, python and C should return the same result. But it's not true. Why?

Python:

>>> pow(-1, 0)
1
Foi útil?

Solução

It's a precedence thing. Google thinks (-1)0 = 1, as does Python:

>>> (-1)**0
1

Any nonzero number raised by the exponent 0 is 1.

Outras dicas

You forgot the parenthesis!

-1 ^ 0 = -(1 ^ 0) = -(1) = -1

because power operator has higher precedence.

But:

(-1)^0 = 1

See on Google

Anything to the power of 0 will result to 1.

Remember BEDMASS. Your google example executes Brackets (1^0) which is 1, then you executed Multiplication, negating your expression in the brackets to -1.

(-10) is the same as saying (-1/-1) which is 1.

In division you substract the exponent of the denominator from the exponent of the numerator. For this rule to hold true all number elevated to the power of zero is 1. 51 / 51 = 50 = 1

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top