note 121871 deleted from language.operators.arithmetic by salathe

From: Date: Mon, 21 Sep 2020 14:58:19 +0000
Subject: note 121871 deleted from language.operators.arithmetic by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-215403@lists.php.net to get a copy of this message
Note Submitter: philippe ---- To get a positiv result function modulo(int $a, int $b):?int { if ($b == 0) { throw new Exception('modulo : second operand must not be zero'); } $b = abs($b); // test $b == 1 for performance when $a < 0 return ($b == 1) ? 0 : (($a < 0) ? modulo($a + $b, $b) : $a % $b); }

« previous php.notes (#215403) next »