Hi.
I think you don't understand what modulo does. The examples you give all suggest you think it is simply integer divide. a % b returns the remainder when the integer a is divided by the integer b. All your 'examples' illustrate correct behavior of the modulo operator.
George
On Aug 5, 2004, at 9:02 PM, Matthew Boehm wrote:
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
[EMAIL PROTECTED]
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!"; ?>
----------------------------------------------------------------------- -----
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php