Re: Modulo Function returns incorrect results

From: Date: Fri, 06 Aug 2004 01:11:26 +0000
Subject: Re: Modulo Function returns incorrect results
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-11950@lists.php.net to get a copy of this message
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 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!"; ?> ---------------------------------------------------------------------------- --PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.internals (#11950) next »