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
5
  • Don't you see what's actually being calculated? In the little calculator area, Google is actually interpreting your input as -(1 ^ 0)
    – Ian
    Aug 19, 2013 at 18:02
  • Hey guys, that's basic math. At least learn how to use a calculator.
    – alk
    Aug 19, 2013 at 18:03
  • 0 power of any_number = 1 Aug 19, 2013 at 18:07
  • Math.pow(-1, 0) (JavaScript) and pow(-1.0, 0) (C) also return 1.
    – nderscore
    Aug 19, 2013 at 18:07
  • 1
    @GrijeshChauhan Zero to the zero is ambiguous: stackoverflow.com/a/17368335/1708801 Aug 19, 2013 at 18:07

5 Answers 5

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.

2
  • 4
    @Dmitry: Because pow(-1, 0) == (-1)**0, not -(1**0). Aug 19, 2013 at 18:00
  • Thank you - it's an answer! :)
    – Dmitry
    Aug 19, 2013 at 18:02
3

You forgot the parenthesis!

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

because power operator has higher precedence.

But:

(-1)^0 = 1

See on Google

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.

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

2
  • Why not 1/1 ? I think you wants to say (-1 ^ 0) == ( -1 ^ (1 -1)) == -1 ^1 * -1 ^ -1 == -1/ -1 Then Nice answer! Aug 19, 2013 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, 2013 at 18:53
0

Please, consider this patterns

    ...
x^3  = x*x*x
x^2  = x*x
x^1  = x
x^0  = ?????
x^-1 = ?????
    ...

    ...
x^3  = 1*x*x*x
x^2  = 1*x*x
x^1  = 1*x
x^0  = 1
x^-1 = 1/x
x^-2 = 1/x/x
x^-3 = 1/x/x/x
    ...

A simple traditional definition of pow function means how many times we multiply a number by self.

But in more strict sense pow function means how many times we multiply or divide the one by a number.

By this reason x^0 = 1 => 0^0 = (-1)^0 = 1 too.

In a more general case the seed may be any number.

static double Pow(double x, int pow, double seed = 1d)
{
    var value = seed;
    
    if (pow < 0)
        for (var i = 0; i > pow; i--) value /= x;
    else
        for (var i = 0; i < pow; i++) value *= x;
    
    return value;
}

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.