普通网友 2010-07-14 08:56
浏览 16
已采纳

$ n = 2; 10- $ n = 87

well this is what i am doing:

$total = (array_sum($odds))+$evens;
$total = str_split($total);
echo 'total[1]: '.$total[1].'<br />';
echo '10-$total[1]: ' . (10-($total[1]));

and the output is:

total[1]: 2
10-$total[1]: 87

my guess is it is being treated as a string, but how do i fix it?

so, what i want to know is
wh does (10-($total[1])); = 87?


Update:
yeah my mistake, a phantom 7,
but can anyone now tell me why:
echo $flybuys.' % '.$check.'<br />';
   $res = $flybuys % $check;
   echo 'res: '.$res;

outputs: 6014359000000928 % 8 res: 7

  • 写回答

4条回答 默认 最新

  • doudian7996 2010-07-14 08:58
    关注

    The inaccurate modulus result is because 6014359000000928 (~2^52) is beyond the bounds of an int, so PHP interprets it as a float. That implies you have a 32-bit system (PHP data type sizes vary depending on architecture). If you need to do math on large numbers, you can use a library like GMP. E.g.:

    $flybuys = gmp_init("6014359000000928");
    $res = gmp_mod($flybuys, 8);
    

    Make sure you pass large numbers to GMP as strings.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题