possible GMP bug?
| From: | Tom Swiss | Date: | Tue, 02 Oct 2007 00:12:46 +0000 |
| Subject: | possible GMP bug? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-262628@lists.php.net to get a copy of this message | ||
I believe I have discovered a bug with the GMP functions. But since
we're sticking with the ancient PHP RedHat gives us (a patched-up 4.3.9),
I'd like to ask others with more modern installations to check if they get
the same behavior. (Then I know whether to pester the PHP folks, or to
pester RedHat to backport some fix. Or, I suppose it could be a bug in our
GMP; again, other datapoints will help figure out where the problem lies.)
Consider the following:
<?php
$total=gmp_init(120);
$v=gmp_mul(1000, 0); // which is, of course, 0. Right? Therein lies the rub.
// $v=gmp_init(0); // if we include this line to make it 0, all's well
echo "before add: total is ".gmp_strval($total).", v is
".gmp_strval($v)."\n";
$total = gmp_add($total,$v);
echo "after add: total should be 120, and is actually:
".gmp_strval($total)."\n";
?>
I run it and I get rather unexpected results:
[white 376] php ~/gmp_test.php
Content-type: text/html
X-Powered-By: PHP/4.3.9
before add: total is 120, v is 0
after add: total should be 120, and is actually: 0
Our PHP is Redhat's 4.3.9-3.22.9; our GMP is gmp-4.1.4-3.
Any help, corroboration, counterexamples, or notification that "you
dummy, you forgot to frob the whoozitz, that's why it doesn't work!", would
be greatly appreciated. Thanks!
-- Tom Swiss / tms(at)infamous.net / www.infamous.net / www.unreasonable.org
"What's so funny about peace, love, and understanding?" - Nick Lowe
"Power to the Peaceful" - Michael Franti