为什么 gmp_mod 在不同平台上产生不同的结果?

发布于 2024-10-06 21:27:52 字数 1350 浏览 0 评论 0原文

请考虑这个片段(与How is 13 % 64= -13)

if(extension_loaded('GMP')) {
    printf("
        PHP Version: %s
        gmp_strval(gmp_mod('-13', '64')) = %s
        gmp_strval(gmp_mod(-13, 64)) = %s
        gmp_mod(-13, 64) = %s
        ",
        phpversion(),
        gmp_strval(gmp_mod('-13', '64')),
        gmp_strval(gmp_mod(-13, 64)),
        gmp_mod(-13, 64)
    );
}

在我的 Win7、x64 上,这会产生

PHP Version: 5.3.3
gmp_strval(gmp_mod('-13', '64')) = 51
gmp_strval(gmp_mod(-13, 64)) = -51
gmp_mod(-13, 64) = -51

奇怪的结果,因为在 http://codepad.viper-7.com/gqN5aa 它只产生 51 。

我找不到 < 的错误PHP Bugtracker 上的 code>gmp_mod。但手册页也没有任何暗示不同的内容可能的结果。我不明白为什么它会产生不同的结果。

请运行上面的代码片段并发布输出以及您正在使用的操作系统和 CPU 架构,以便我可以确认这不仅仅是我的机器出现问题。

另外,如果您知道这是否是已知问题甚至预期行为,请指出错误跟踪器中的链接。否则我会用收集的结果打开一个错误。

谢谢!

PS,请告诉我是否应该为此请求 CW。否则我会将 bugtracker 的链接作为答案(除非有人提出令人信服的解释)。

Please consider this snippet (related to How is 13 % 64= -13)

if(extension_loaded('GMP')) {
    printf("
        PHP Version: %s
        gmp_strval(gmp_mod('-13', '64')) = %s
        gmp_strval(gmp_mod(-13, 64)) = %s
        gmp_mod(-13, 64) = %s
        ",
        phpversion(),
        gmp_strval(gmp_mod('-13', '64')),
        gmp_strval(gmp_mod(-13, 64)),
        gmp_mod(-13, 64)
    );
}

On my Win7, x64 this produces

PHP Version: 5.3.3
gmp_strval(gmp_mod('-13', '64')) = 51
gmp_strval(gmp_mod(-13, 64)) = -51
gmp_mod(-13, 64) = -51

which is odd, because on http://codepad.viper-7.com/gqN5aa it produces just 51 .

I could not find a bug for gmp_mod on the PHP Bugtracker. But there is also nothing at the manual page hinting at different possible outcomes. And I don't see why it should produce different results.

Please run the above code snippet and post the output along with which Operating System and CPU Architecture you are using, so I can confirm it is not just my machine acting up.

Also, if you know whether this a known issue or even expected behavior, please point me to a link in the bugtracker. Otherwise I will open a bug with the collected results.

Thanks!

P.S. please let me know if I should request CW for this. Otherwise I will put the link to the bugtracker as the answer (unless someone comes up with a compelling explanation).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆沫 2024-10-13 21:27:52

这是扩展本身的错误。几周前,当我遇到同样的问题时,我偶然发现了此错误报告,并得出结论,这实际上是扩展中的一个错误。我已经尝试使用最新的快照,效果很好。

PHP Version: 5.3.5-dev
gmp_strval(gmp_mod('-13', '64')) = 51
gmp_strval(gmp_mod(-13, 64)) = 51
gmp_mod(-13, 64) = 51

It's a bug in the extension itself. I stumbled upon this bug report when I had the same issue a few weeks ago, and concluded it was in fact a bug in the extension. I have tried with the latest snapshot, and it works fine.

PHP Version: 5.3.5-dev
gmp_strval(gmp_mod('-13', '64')) = 51
gmp_strval(gmp_mod(-13, 64)) = 51
gmp_mod(-13, 64) = 51
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文