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][1] 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;
}
[1]: https://sharplab.io/#v2:C4LgTgrgdgNAJiA1AHwAICYCMBYAUH1TATgAoAiQgAgEkBbABwBsBTW5qYAQ2AEsB7KGQCUAbjx4AZnzCUSAN04yelALyUADCMrKAPJQDMWnokRC8AbzyVrlQqVFWbdkgBIy5ngF8AeiQC06EKqlOYAstwAFgB0AAp8AO4kPDCUAUKewmK4NrbEru5evn6YQWphkbEJSSnF6ZmO1s5uHj4k6qUh4cDRcYnJGnUO2U55zYUkJcHl3ZV9KSUZQzlNBa2BU109Vf2Bi1me4rjOQwR5ZADCEADOwHy0NAwsbBzc/IInuFIy8orawZp/PSGbQmMy4SzDRp5JYjUhjVppKa9aqpXb1SG5OGrIqTMrI/q1PYNTH5Fq+dpI7YpdpEjErMkTDrmfHzQZZZajbEkdZ4qmUNFDA74I6YABslDgfAgACMWJRkZKZXKAB4pHgcSj0BIpRWy5iUK7MZhwYKYOBgiE5BQyBSMCD6tSG43smzEngSWRa+KUPTtYk5L6ya1/NQA5QAPk1CSMfj8QVt9soAHo1MqXdZmIxDf6bIGfkp/kYfVH4kZQZQE/qAFSp9OUYmoADsFc4duY+yAA=
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][1] 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;
}
[1]: https://sharplab.io/#v2:C4LgTgrgdgNAJiA1AHwAICYCMBYAUH1TATgAoAiQgAgEkBbABwBsBTW5qYAQ2AEsB7KGQCUAbjx4AZnzCUSAN04yelALyUADCMrKAPJQDMWnokRC8AbzyVrlQqVFWbdkgBIy5ngF8AeiQC06EKqlOYAstwAFgB0AAp8AO4kPDCUAUKewmK4NrbEru5evn6YQWphkbEJSSnF6ZmO1s5uHj4k6qUh4cDRcYnJGnUO2U55zYUkJcHl3ZV9KSUZQzlNBa2BU109Vf2Bi1me4rjOQwR5ZADCEADOwHy0NAwsbBzc/IInuFIy8orawZp/PSGbQmMy4SzDRp5JYjUhjVppKa9aqpXb1SG5OGrIqTMrI/q1PYNTH5Fq+dpI7YpdpEjErMkTDrmfHzQZZZajbEkdZ4qmUNFDA74I6YABslDgfAgACMWJRkZKZXKAB4pHgcSj0BIpRWy5iUK7MZhwYKYOBgiE5BQyBSMCD6tSG43smzEngSWRa+KUPTtYk5L6ya1/NQA5QAPk1CSMfj8QVt9soAHo1MqXdZmIxDf6bIGfkp/kYfVH4kZQZQE/qAFSp9OUYmoADsFc4duY+yAA=