acos(1) returns NAN in some conditions
Found the solution. It seems that the problem is related to precision. If I make sure that $dist
is within [-1,1]
range, it works fine:
$dist = acos(min(max($dist,-1.0),1.0));
Working example: https://3v4l.org/dlunK