Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 multiple difference - previousStep by itself because i'm just squaring it, but if i need to bring it to the Nth power, then this would be a problem. So why can't you ^ doubles and is there a way around this?

like image 603
MagnusCaligo Avatar asked Dec 25 '22 08:12

MagnusCaligo


1 Answers

The ^ operator isn't the exponentiation operator in Java; it's the bitwise XOR operator, which doesn't make much sense with double arguments.

You can either multiply the value by itself or you can call Math.pow(yourValue, 2) for exponentiation.

like image 82
rgettman Avatar answered Dec 28 '22 08:12

rgettman