Wolfram Alpha说,将为以下公式给出正确的结果:

((0.0004954*($current^2))-((0.935*$current)+378.486))-
((0.0004954*($desired^2))-((0.935*$desired)+378.486));

但是,当我在PHP中运行它时,它没有给出正确的答案,为什么不呢?
$current = mysql_escape_string($_POST['current']);
$desired = mysql_escape_string($_POST['desired']);
$username = mysql_escape_string($_POST['username']);
$password = mysql_escape_string($_POST['password']);
$email = mysql_escape_string($_POST['email']);
$ip = $_SERVER["REMOTE_ADDR"];
$time = time();
$elo = $desired - $current;
if($current < 1200) {
  $price = ($elo/100)*30;
} elseif($current < 1400) {
  $price = ($elo/100)*35;
} elseif($current < 1901) {
  $price = ((0.0004954*($current^2))-((0.935*$current)+378.486))-((0.0004954*($desired^2))-((0.935*$desired)+378.486));
}

最佳答案

^运算符是bitwise运算符。

您需要使用pow

如果您只想平方一个值,则可以将其本身乘以$current * $current

关于php - php,使用脱字符号(^)计算指数失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14371386/

10-13 23:05