- var_dump: documentation ( source)
- sin: documentation ( source)
- cos: documentation ( source)
- acos: documentation ( source)
- max: documentation ( source)
- min: documentation ( source)
- deg2rad: documentation ( source)
<?php
$lat1 = 35.697959;
$lat2 = 35.697959;
$lon1 = 139.707085;
$lon2 = 139.707085;
$theta = $lon1 - $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
var_dump($dist); // returns 1
$dist = acos(min(max($dist,-1.0),1.0));
var_dump($dist); // returns NAN
$x = 1;
$x = acos($x);
var_dump($x); // doesn't return NAN