note 76231 deleted from language.operators.arithmetic by hholzgra

From: Date: Thu, 02 Aug 2012 15:06:34 +0000
Subject: note 76231 deleted from language.operators.arithmetic by hholzgra
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-189814@lists.php.net to get a copy of this message
Note Submitter: nicolas_rainard_NOSPAM at yahoo dot fr ---- gilthansREMOVEME at gmail dot com proposed a nice integer division function, but its speed greatly depends on the size difference between the two provided numbers. If the first number is very big and the second one is very small, this function will take a (relative) long time to resolve (because of the loop). Here is another integer division function, wich always takes the same time to resolve, what ever the provided numbers are. In most cases, it will be faster, but if the numbers are close, the other one will be twice as fast. It's up to you to choose one of these functions, depending on the expected input numbers... function int_divide($x, $y) { if ($x == 0) return 0; if ($y == 0) return FALSE; $result = $x/$y; $pos = strpos($result, '.'); if (!$pos) { return $result; } else { return (int) substr($result, 0, $pos); } }

« previous php.notes (#189814) next »