views:

195

answers:

4

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?

+5  A: 

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

soulmerge
+2  A: 

The ^ operator is the bitwise XOR operator. You have to use either pow, bcpow or gmp_pow:

var_dump(pow(10, -0.01));  // float(0.977237220956)
Gumbo
I tried using bcpow. No luck.
Kuroki Kaze
And it seems like gmp_pow accepts only positive powers. Of course, we can convert in to 1/gmp_pow('10', '.01') :)
Kuroki Kaze
A: 

The bcpow function only supports integer exponents. Try using pow instead.

Rob
+1  A: 

I had the same problem, check the answers in my question. =)

Alix Axel