Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:11952 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 71981 invoked by uid 1010); 6 Aug 2004 02:04:05 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 71903 invoked from network); 6 Aug 2004 02:04:04 -0000 Received: from unknown (HELO theta.altoona-pa.com) (209.161.72.28) by pb1.pair.com with SMTP; 6 Aug 2004 02:04:04 -0000 Received: from IONZOFT-JEG (dpvc-207-68-114-163.alt.east.verizon.net [207.68.114.163]) by theta.altoona-pa.com (Postfix) with ESMTP id 1B97E16870 for ; Thu, 5 Aug 2004 22:04:04 -0400 (EDT) Date: Thu, 5 Aug 2004 22:04:09 -0400 X-Mailer: The Bat! (v2.11.02) Business Reply-To: Jason Garber Organization: IonZoft, Inc. X-Priority: 3 (Normal) Message-ID: <995802514.20040805220409@ionzoft.com> To: internals@lists.php.net In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Modulo Function returns incorrect results From: jason@ionzoft.com (Jason Garber) Hello Matthew, 3/4 = (0*4)+3 --> 3%4 = 3 9/4 = (2*4)+1 --> 9%4 = 1 20/10 = (2*10)+0 --> 20%10 = 0 4 goes into 3 a total of ZERO times with a remainder of 3. 10 goes into 20 a total of TWO times with a remainder of 0. Take a look at a standard (integer) long division problem with remainders. -- Best regards, Jason mailto:jason@ionzoft.com Thursday, August 5, 2004, 9:02:04 PM, you wrote: MB> Found some weird behavior in the built in mod function (%): MB> $a = 4; MB> $b = 3; MB> print ( $a % $b ); (returns 1 as it should) MB> Now swap $a and $b: MB> $a = 3; MB> $b = 4; MB> print ( $a % $b ); MB> This returns 3. 3?! 3/4 is 0.75. Shouldn't this return 0? MB> Try this one: MB> $a = 20; MB> $b = 10; MB> print ( $a % $b ); MB> Shouldn't that return 2? It returns 0; MB> $a = 11; MB> $b = 21; MB> print ( $a % $b ); MB> Returns 11. What is going on? Was my C.S. Professor wrong in telling us MB> that the % function returns the left side of the decimal in a division? MB> This is PHP 4.3.4 MB> Any help would be appreciated. MB> Thanks, MB> Matthew MB> -- MB> ---------------------------------------------------------------------------- MB> Matthew Boehm MB> dr_mac@mail.utexas.edu MB> The University of Texas at Austin, Department of Geography MB> "Why did the prison use Windows2K as a guard? Because it always locks up!" MB> MB> ----------------------------------------------------------------------------