I have a function to calculate distance by coordinates
Private Function CalcularDistancia(ByVal X As Double, ByVal Y As Double, ByVal X2 As Double, ByVal Y2 As Double) As Double
Dim pi As Double = 3.1415926535897931
Dim X_1, X_2, Y_1, Y_2, DistanciaTotal As Double
X_1 = ((90 - X) * pi) / 180
X_2 = ((90 - X2) * pi) / 180
Y_1 = (Y * pi) / 180
Y_2 = (Y2 * pi) / 180
DistanciaTotal = Acos(Cos(X_1) * Cos(X_2) + Sin(X_1) * Sin(X_2) * Cos(Y_1 - Y_2)) * 6371
Return DistanciaTotal
End Function
The error seems to happen when both coordinates are the same but no always. I don't receive any error but a -1.#IND(Indeterminate NaN) instead. I don't see any division by zero or something illegal in my function.
How I can debug this?