-1

I have the weirdest thing in PHP.

I have a function like this:

function Calculate_i_from_IDF($coef, $Tc)
{
    print_r($coef);
    $intensity=$coef[0]+$coef[1]*$Tc+$coef[2]*$Tc^2+$coef[3]*$Tc^3+$coef[4]*$Tc^4;
    echo "intensity=$intensity<P>";
    return $intensity;
}

My Tc=1. The result is:

Array ( [0] => 1.1413387743 [1] => -0.7177898193 [2] => 0.6190050656 [3] => -0.4272211298 [4] => 0.0813729821 )

intensity=7

What I don't understand is why $intensity is 7 instead of the expected 0.696706. It is so weird! Any help is greatly appreciated.

Thank you,

Frank

Mitch
  • 21,223
  • 6
  • 63
  • 86
Frank
  • 11
  • 2

1 Answers1

1

^ is not the exponent operator, but a bitwise operator. That is likely causing the expression to result in an integer. Try using pow.

Related: Php, calculating exponent with carrot (^) fails

Community
  • 1
  • 1
Mitch
  • 21,223
  • 6
  • 63
  • 86
  • Wow. It is that simple! Thank you so much! You saved my day. – Frank Jan 18 '15 at 03:26
  • 1
    @Frank, I'm glad to hear it. If that solved your problem, you can accept it as an answer by clicking the green checkmark. See http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – Mitch Jan 18 '15 at 03:30
  • Frank . please accept it as an answer. So many people get the answer/help they're looking for and fail to acknowledge the individual who helped them. – terary Jan 18 '15 at 03:35