Why does gmp_mod produce differerent results on different platforms?
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 act开发者_如何学运维ing 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).
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
精彩评论