Numerical Underflow
I'm doing some calculations in php, and seem to be having a problem with either overflow, or underflow (small # gets rounded to 0). It works for some values, but for others, gives me a huge number, usually in the billions. Is it possible in php to specify the use of a higher precision datatype, or how else can I avoid this problem in php?
This is the function which seems to be causing the problem:
//calculate the distance between two latitude, logitude coordinates. +ve is N,E
function latlonradiandistance($lat1,$lon1, $lat2,$lon2){
$r = 6378100; //radius of earth in meters
return acos(cos($lat1)*cos($lon1)*cos($lat2)*co s($lon2) + cos($lat1)*sin($lon1)*cos($lat2)*sin($lo n2) + sin($lat1)*sin($lat2)) * $r;
}
[edit] Resolved. Thanks for the suggestions.
This is the function which seems to be causing the problem:
//calculate the distance between two latitude, logitude coordinates. +ve is N,E
function latlonradiandistance($lat1,$lon1, $lat2,$lon2){
$r = 6378100; //radius of earth in meters
return acos(cos($lat1)*cos($lon1)*cos($lat2)*co
}
[edit] Resolved. Thanks for the suggestions.
