Talk:Visual Basic/Simple Arithmetic

Here is the previous version of the atan2 routine. It has been suggested that this routine is faulty and the originator even notes that comparison with zero doesn't work (not exactly true: the comparison works but the consequences are not as expected because of limited dynamic range):

Public Function Atan2(ByVal Y As Double, ByVal X As Double) As Double Dim signy as Integer signy = Sgn(Y) If signy = 0 Then signy = 1 ' removes the problem when Y=0 If Abs(X) < 0.0000001 Then ' (direct comparison with zero doesn't always work) Atan2 = Sgn(Y) * 1.5707963267949 ElseIf X < 0 Then Atan2 = Atn(Y / X) + signy * 3.14159265358979 Else Atan2 = Atn(Y / X)    End If End Function

--10:39, 28 August 2007 (UTC)