Php fancy math

I get unexpected values ​​for calculation variables:

$var1 = $var2 * (((1 + $var3)^$var4)^$var5); 

I checked that $var2 is 3, $var3 is 0.1, $var4 is 1, $var5 is 1.1, so

$var1 = 3*(((1+0.1)^1)^1.1) = 3.3316 , but in PHP, $var1 = 3

if I change $var4 to 2,

$var1 = 3*(((1+0.1)^1)^1.1) = 3.6999 , but in PHP, $var1 = 6

Why is this? Any ideas? I tried to explicitly declare all variables as float.

+4
source share
1 answer

Note that ^ not a "force." You can see the pow function .

( ^ is actually a " bitwise exception or ".)

+13
source

All Articles