dingus Posted April 24, 2008 Share Posted April 24, 2008 hey i have a small problem with the exp function basically its dealing with a relay small number (in the order of 1.2E-300) problem is when i pass that number to the exp function it is returning zero is there a way to get around it? Link to comment https://forums.phpfreaks.com/topic/102761-exp-returning-zero/ Share on other sites More sharing options...
rhodesa Posted April 24, 2008 Share Posted April 24, 2008 I can't reproduce the problem. Can you provide a sample of code? Link to comment https://forums.phpfreaks.com/topic/102761-exp-returning-zero/#findComment-526374 Share on other sites More sharing options...
dingus Posted April 25, 2008 Author Share Posted April 25, 2008 ok have have an inverse chi square distribution block that looks like this <?php function inv-chi2( $x, $v) { $m = (double)$x / 2.0; $s = exp(-$m); $t = $s; for($i=1; $i < ($v/2);$i++) { $t *= $m/$i; $s += $t; } return ( $s < 1.0) ? $s : 1.0; } ?> i know its not perfect butt it worked now ging into that the value of $x = 1895.74465264 and $v = 2468 when we get to the exp function $m = 947.872326318 how ever after exp(-$m); $s becomes zero anyone have any ideas there? Link to comment https://forums.phpfreaks.com/topic/102761-exp-returning-zero/#findComment-526720 Share on other sites More sharing options...
Fadion Posted April 25, 2008 Share Posted April 25, 2008 If i made the right calculations, the result of exp(-$m) where $m = 1895.74465264 / 2 is ~ 2.19e412, but from the manual: The size of a float is platform-dependent, although a maximum of ~1.8e308 with a precision of roughly 14 decimal digits is a common value (the 64 bit IEEE format). Guess thats why ure getting 0 as a result. Link to comment https://forums.phpfreaks.com/topic/102761-exp-returning-zero/#findComment-526731 Share on other sites More sharing options...
dingus Posted April 25, 2008 Author Share Posted April 25, 2008 well at least now i know why im geting zero next question is how to get somthing that isnt zero anyone have any ideas on that Link to comment https://forums.phpfreaks.com/topic/102761-exp-returning-zero/#findComment-526737 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.