- Home /
power of problem java
So I made this basic script to test power of 0.
#pragma strict
function Start () {
var i = 2;
var b = 4;
var a = i-b;
print((i-b)^0);
print(a^0);
}
but it's outputing
-2
and
-2
when mathimaticly it should be
1
and
1 maybe -1 if it sees a as -2 vs (-2) which hopefully it does a = -2, so you can get a negative value vs always positives.
Answer by rameshp · Mar 19, 2015 at 07:40 AM
Use the Math.Pow((i-b),0) instead
Yep. The ^ is a bitwise operator and does something entirely different than power. :)
there still is a problem the math power of function only gives back positive numbers when using the power of 0.
Please check how you are using it. It works for me when I use it like this :
console.log(-$$anonymous$$ath.pow(3,0));
This works when you're working with other powers of negative numbers as well. Let me know if there's another way of doing it
Your answer
![](https://koobas.hobune.stream/wayback/20220613190608im_/https://answers.unity.com/themes/thub/images/avi.jpg)