The ^ operator is undefined for arguments

(((difference - previousStep)/1000)^2)
//difference and previousStep are both doubles

Why can't I use the ^ operator with doubles? I just want to know why. Luckily for me, I can just have a few differences - the previous step on its own, because I just squared it, but if I need to bring it to the N-th power, then this will be a problem. So why can't you double and is there a way around this?

+4
source share
2 answers

The operator is ^not an exponential operator in Java; it is a bitwise XOR operator that doesn't make much sense with arguments double.

, Math.pow(yourValue, 2) .

+10

^ Java, Math.pow(((difference - previousStep)/1000), 2)

0

Source: https://habr.com/ru/post/1542262/


All Articles