Modulo Function returns incorrect results
| From: | Matthew Boehm | Date: | Fri, 06 Aug 2004 01:02:04 +0000 |
| Subject: | Modulo Function returns incorrect results | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-11949@lists.php.net to get a copy of this message | ||
Found some weird behavior in the built in mod function (%):
$a = 4;
$b = 3;
print ( $a % $b ); (returns 1 as it should)
Now swap $a and $b:
$a = 3;
$b = 4;
print ( $a % $b );
This returns 3. 3?! 3/4 is 0.75. Shouldn't this return 0?
Try this one:
$a = 20;
$b = 10;
print ( $a % $b );
Shouldn't that return 2? It returns 0;
$a = 11;
$b = 21;
print ( $a % $b );
Returns 11. What is going on? Was my C.S. Professor wrong in telling us
that the % function returns the left side of the decimal in a division?
This is PHP 4.3.4
Any help would be appreciated.
Thanks,
Matthew
--
----------------------------------------------------------------------------
Matthew Boehm
dr_mac@mail.utexas.edu
The University of Texas at Austin, Department of Geography
"Why did the prison use Windows2K as a guard? Because it always locks up!"
<?PHP echo "PHP kicks ASP!"; ?>
----------------------------------------------------------------------------