note 16998 deleted from language.operators by zak

From: Date: Wed, 21 Nov 2001 18:49:11 +0000
Subject: note 16998 deleted from language.operators by zak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-21115@lists.php.net to get a copy of this message
TO the editor : php@vanvett.net does not know anything about divisions. His post just mess up the manual. The div operator complements the modulo operator. They are not the same. So for those of you who know nothing about integer division : if $a and $b are integers (any of which can be positive OR negative). $mod = $a%$b; $div = (int)($a/$b); and we have $a == $div * $b + $mod is TRUE! Note that % is not the usual modulo mathematical operator because it can return negative numbers! but the div operator given by d_reniers@hotmail.com complements php % operator just fine. if you do not want negative remainders use function mod($a,$b){ $mod = $a%$b; if($mod<0) $mod +=abs($b); return $mod; } Now the corresponding div operator becomes function div($a,$b){ if($b<0) return (int)ceil($a/$b); else return (int)floor($a/$b); } You still have $a == $div*$b+$mod for all integers either positive or negative Ivan

« previous php.notes (#21115) next »