Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:11950 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 23896 invoked by uid 1010); 6 Aug 2004 01:11:48 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 23871 invoked from network); 6 Aug 2004 01:11:48 -0000 Received: from unknown (HELO mail.omniti.com) (66.80.117.3) by pb1.pair.com with SMTP; 6 Aug 2004 01:11:48 -0000 Received: from ([66.80.117.254:45123]) by mail.omniti.com (ecelerity HEAD) with SMTP id 7B/41-21951-5DAD2114; Thu, 05 Aug 2004 21:11:52 -0400 In-Reply-To: References: Mime-Version: 1.0 (Apple Message framework v618) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-ID: <8A386B6C-E745-11D8-84F8-000D93359332@omniti.com> Content-Transfer-Encoding: 7bit Cc: George Schlossnagle , Date: Thu, 5 Aug 2004 21:11:26 -0400 To: Matthew Boehm X-Mailer: Apple Mail (2.618) Subject: Re: [PHP-DEV] Modulo Function returns incorrect results From: george@omniti.com (George Schlossnagle) 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 Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >