奇怪的pow()php bug

时间:2012-12-30 19:26:29

标签: php

我有这段PHP代码:

$skill_amount = round(pow($rarity,1.25));

应该注意,$ rarity是从查询中获得的。

我正在输入0,2,4,8,16,32,64之类的值。

99%的工作时间,但我的用户报告巨大价值的次数很少,如:

13771,77936

可能导致这种情况的原因是什么?

2 个答案:

答案 0 :(得分:7)

"What could possibly be causing this?"

$rarity的大或意外值。

如果你可以检查$ rarity的所有可能值,你应该这样做。否则,你可以做一些基本的调试。

if ($skill_amount > some sane value) {
    // log $skill_amount & $rarity to a file or email
    // maybe also some other investigative values, like stuff that assisted the derivation of $rarity
}

答案 1 :(得分:1)

在此脚本中没有发现任何问题,因此我同意需要对$ rarity进行健全性检查。

<?php // RAY_temp_amy_neville.php
error_reporting(E_ALL);
echo '<pre>';

$range = range(1, 4096);
foreach ($range as $rarity)
{
    $skill_amount = round(pow($rarity,1.25));
    $out[$rarity] = $skill_amount;
}
print_r($out);
相关问题