Raising to power in PHP

Kuroki Kaze picture Kuroki Kaze · Jul 31, 2009 · Viewed 9.9k times · Source

Well, i need to do some calculations in PHP script. And i have one expression that behaves wrong.

echo 10^(-.01);

Outputs 10

echo 1 / (10^(.01));

Outputs 0

echo bcpow('10', '-0.01') . '<br/>';

Outputs 1

echo bcdiv('1', bcpow('10', '0.01'));

Outputs 1.000....

I'm using bcscale(100) for BCMath calculations.

Excel and Wolfram Mathematica give answer ~0,977237.

Any suggestions?

Answer

soulmerge picture soulmerge · Jul 31, 2009

The caret is the bit-wise XOR operator in PHP. You need to use pow() for integers.