View Full Version : ACOS or ArcCos


Runutts2
08-28-2002, 04:04 AM
Having problems with ACOS worksheet function, when I use the ACOS function is gives me #Name? error. I have the MSowcf.dll file referenced but still did not work. I found another Code which uses the ArcCos function but it returns the wrong value. The code for the ArcCos function is as Follows:

Function ArcCos(X As Double) As Double
' Inverse Cosine
If X = 1 Then
ArcCos = 0
ElseIf X = -1 Then
ArcCos = -PI()
Else
ArcCos = Atn(X / Sqr(-X * X + 1)) + PI() / 2
End If
End Function

but the result is not correct in radians or degrees.

thanks in advance

Travis
08-28-2002, 07:59 AM
Try this:


Public Function ArcCOS(ByVal nValue As Double, Optional fRadians As Boolean = True) As Double
Const PI As Double = 3.14159265359
ArcCOS = -Atn(nValue / Sqr(1 - nValue * nValue)) + PI / 2
If fRadians = False Then ArcCOS = ArcCOS * (PI / 180)
End Function

Runutts2
08-28-2002, 07:44 PM
Thanks Travis for the quick reply, that was the ticket. Now it gives me the answer that I was expecting.