dingus Posted June 2, 2008 Share Posted June 2, 2008 ok my problem is simple i have a bcmul function that gets hit on average 8500 times in an iteration of a script i need to know if there is a faster way to multiply to arbotrey numbers (0.00045) in php so it dosent take a minuet to run the script Link to comment https://forums.phpfreaks.com/topic/108329-bcmul-issues/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 2, 2008 Share Posted June 2, 2008 If you were to post an example of what the data and results look like and your code, someone could directly help. Perhaps your existing code just needs to be optimized for execution speed, but we cannot tell without seeing it. Perhaps for the range of values, a different method could be used, but we cannot tell without seeing what your values and results look like. Link to comment https://forums.phpfreaks.com/topic/108329-bcmul-issues/#findComment-555384 Share on other sites More sharing options...
dingus Posted June 2, 2008 Author Share Posted June 2, 2008 ok i'm dealing with a chi2 function which loops like this <?php function chi2Q( $x, $v) { bcscale(0); $m = bcdiv($x , '2.0'); bcscale(ceil(bcmul('0.8686' , $m))); $s = bcdiv('1' , bcpow('2.718282', $m)); $t = $s; $k = ceil(bcdiv($v,2)); for($i=1; $i < $k;$i++) { $p = bcdiv($m,$i); //$p = $m/$i; $t = bcmul($t, $p); //$t = $t*$p; $s = bcadd($s,$t); //$s = $s+$t; } return $s ; } ?> where $x is the value and $v is the degrees of freedom now the issue exists at this line $t = bcmul($t, $p); as you can see i initially used conventional maths to speed up the process how ever i was getting arithmetic underflow problems which lead me to bc maths i'm deliberately setting bcscale to the minimum number of dec places i will need to optimize as best i can anyone with any suggestions on how to improve this i would greatly appropriated it Link to comment https://forums.phpfreaks.com/topic/108329-bcmul-issues/#findComment-555390 Share on other sites More sharing options...
dingus Posted June 2, 2008 Author Share Posted June 2, 2008 *bumb* Link to comment https://forums.phpfreaks.com/topic/108329-bcmul-issues/#findComment-556107 Share on other sites More sharing options...
DarkWater Posted June 3, 2008 Share Posted June 3, 2008 Well, arbitrary precision math always takes longer, especially if you're running it 8500 times. There's really not too much you can do there. Link to comment https://forums.phpfreaks.com/topic/108329-bcmul-issues/#findComment-556116 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.