ACOS or ArcCos

Runutts2

Registered User.
Local time
Today, 20:53
Joined
Aug 28, 2002
Messages
13
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
 
Try this:

Code:
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
 
Thanks Travis for the quick reply, that was the ticket. Now it gives me the answer that I was expecting.
 

Users who are viewing this thread

Back
Top Bottom