acos(1) returns NAN in some conditions
问题 Here's my code: <?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($dist); var_dump($dist); // returns NAN As you can see from the comments, $dist is equal to 1 after the calculation, but when I apply acos() it returns NAN . If I try to replicate it manually, it works just fine: