0

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
Dmitry
  • 2,989
  • 2
  • 24
  • 34

4 Answers4

9

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.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
3

You forgot the parenthesis!

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

because power operator has higher precedence.

But:

(-1)^0 = 1

See on Google

Grijesh Chauhan
  • 57,103
  • 20
  • 141
  • 208
julienc
  • 19,087
  • 17
  • 82
  • 82
1

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.

clamchoda
  • 4,411
  • 2
  • 36
  • 74
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

Grijesh Chauhan
  • 57,103
  • 20
  • 141
  • 208
edi_allen
  • 1,878
  • 1
  • 11
  • 8
  • Why not `1/1` ? I think you wants to say `(-1 ^ 0)` == `( -1 ^ (1 -1))` == `-1 ^1 * -1 ^ -1` == `-1/ -1` Then Nice answer! – Grijesh Chauhan Aug 19 '13 at 18:10
  • What I meant was that (-1^0) == **((-1^1) / (-1^1))**. Applying the rule of exponent to the second expresion give you -1^0 which is 1. Every number divided by itself equal 1 (except for zero). – edi_allen Aug 19 '13 at 18:53