dingus Posted April 27, 2008 Share Posted April 27, 2008 hey guys i have a inverse chi square function that is running takeing quite a long time to run it currently looks like this function chi2Q( $x, $v) { bcscale(1500); $m = bcdiv($x , '2.0'); $s = bcdiv('1' , bcpow('2.718282', $m)); $t = $s; for($i=1; $i < (bcdiv($v,2));$i++) { $t = bcmul($t, bcdiv($m,$i)); $s = bcadd($s,$t); } return $s ; } no i need to use bcmath to stop a underflow problem from with in that function..... and i have no idea how to incrse the speed of this function the for loop is looping around 10000 times now i have tryed using gmp to do it except that only supports really big numbers not really small ones (only works with int as fare as i can work out) can anyone help me speed this up? Link to comment https://forums.phpfreaks.com/topic/103120-speeding-up-a-function/ Share on other sites More sharing options...
Barand Posted April 27, 2008 Share Posted April 27, 2008 Evaluate the loop end condition once instead of every loop $k = bcdiv($v,2); for($i=1; $i < $k; $i++) { $t = bcmul($t, bcdiv($m,$i)); $s = bcadd($s,$t); } Link to comment https://forums.phpfreaks.com/topic/103120-speeding-up-a-function/#findComment-528213 Share on other sites More sharing options...
dingus Posted April 27, 2008 Author Share Posted April 27, 2008 ok that is helpful but the biggest delay is on the bc function to calculate $t is there anyway i can speed that one up? Link to comment https://forums.phpfreaks.com/topic/103120-speeding-up-a-function/#findComment-528309 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.