note 99112 deleted from language.operators.arithmetic by hholzgra

From: Date: Thu, 02 Aug 2012 15:07:43 +0000
Subject: note 99112 deleted from language.operators.arithmetic by hholzgra
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-189823@lists.php.net to get a copy of this message
Note Submitter: crazycat at c-p-f dot org ---- I notice a trouble with the modulus operator, when trying to work with great values: <?php function modulo($val, $div) { $r = $val - (floor($val/$div)*$div); return $r; } $values = array(375389654, 50856937683); $divs = array(2, 16, 62); foreach ($values as $v) { foreach ($divs as $d) { echo $v, '%', $d, ' gives ', modulo($v, $d), ' but get ', ($v%$d), '<br />'; } } ?> And output : <?php /* 375389654%2 gives 0 but get 0 375389654%16 gives 6 but get 6 375389654%62 gives 52 but get 52 50856937683%2 gives 1 but get -1 50856937683%16 gives 3 but get -13 50856937683%62 gives 27 but get -21 */ ?>

« previous php.notes (#189823) next »