【问题标题】:PHP Modulus with Overflow Integer带有溢出整数的 PHP 模数
【发布时间】:2013-07-24 17:19:48
【问题描述】:

我从乘法中得到整数溢出值7.233907357909E+16

现在我需要计算模数7.233907357909E+16 % 15

我该如何解决它,知道该怎么做吗?

【问题讨论】:

  • 你是如何获得这些值的
  • 你可以使用PHP的fmod()函数
  • 乘法前取模。一旦你离开了整数精确表示的范围,你就丢失了信息。

标签: php math modulus


【解决方案1】:

You should look into bcmul and bcmod for arbitrary precision computations.

Example:

$res = bcmul('134334244395933282', '2834783723423487283');
$modRes = bcmod($res, '15');
echo $modRes;

【讨论】:

    猜你喜欢
    • 2011-06-04
    • 2012-02-04
    • 2020-03-27
    • 1970-01-01
    • 1970-01-01
    • 2023-01-03
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多