hi guys,
i'm looking for the fastest way to do an integer division in php. for example, 5 / 2 schould be 2 | 6 / 2 should be 3 and so on. if i simply do this, php will return 2.5 in the first case, the only solution i could find was using intval($my_number/2)
- wich isn't as fast as i want it to be (but gives the expected results).
can anyone help me out with this?
EDIT: tanks to all of you for your ideas, i used the script postet by rubber_boots to test some of them with 10000000 iterations, here you can see the results (MAMP on a 3 or 4 year old macbook with 2Ghz intel core 2 duo):
start (10000000)
(int)...: 2.26 sec
floor(): 4.36 sec
int_divide(): 2.86 sec
bit-shift: 1.45 sec
intval(): 4.51 sec
round() with PHP_ROUND_HALF_DOWN: 5.48 sec
until now, bit-shift is the fastest way, but i'll leave this question open for a day to see if there are other possibilitys for this...
EDIT2: updated the results, added round() with PHP_ROUND_HALF_DOWN (thanks to Col._Shrapnel)