doujiao1948 2015-01-18 03:17
浏览 22
已采纳

为什么结果总是整数?

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

  • 写回答

1条回答 默认 最新

  • duanfang7270 2015-01-18 03:22
    关注

    ^ 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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn