hello all i need to get the tangent of a circle command into a programe as follows tan (angle of degree/2)

trying just 90degrees /2 =45degrees tan(45) in intermediate window i get 1.619 which is radians , to convert to degrees its 180/pi (3.142) but this gives result of 92.806. rather than 1

if using windows calculator tan 45 =1 which is correct, but have tried all ways to try and get tan command to give the same result , so how can this be done.

thank you

Dani AI

Generated

Good point from — the missing step is converting the input angle from degrees into radians before calling the tangent function. Trig functions in most programming libraries take radians; the tangent function returns a ratio (no units). Converting the numeric result of tan(...) into degrees is the wrong move. To get an angle back from a ratio use the inverse tangent (atan) and then convert that result to degrees.

Here are minimal, copy‑and‑paste examples:

import math

deg = 45
rad = math.radians(deg)        # or deg * math.pi / 180
print(math.tan(rad))           # ≈ 1.0

# inverse example: ratio -> degrees
print(math.degrees(math.atan(1)))  # 45.0
' VB.NET
Dim deg As Double = 45
Dim rad As Double = deg * Math.PI / 180.0
Dim t As Double = Math.Tan(rad)
Console.WriteLine(t)              ' ~1.0

' inverse
Dim angleDeg As Double = Math.Atan(1) * 180.0 / Math.PI
Console.WriteLine(angleDeg)       ' 45.0
' VB6 / VBA
Public Function DegToRad(d As Double) As Double
    DegToRad = d * 3.14159265358979 / 180#
End Function

Debug.Print Tan(DegToRad(45))      ' ~1
Debug.Print Atn(1) * 180 / 3.14159265358979  ' 45

Troubleshooting tips: (1) Check your calculator or IDE mode (deg vs rad). (2) Expect tiny floating‑point errors (use rounding or an equality tolerance when comparing). (3) If you ever see a strange number after calling tan, verify whether you accidentally passed degrees where radians were expected — that’s the exact confusion ran into. For further reference see ’s pointer to documentation on command syntax.

Recommended Answers

All 3 Replies

The tan function is expecting the argument to be in radians so convert your 45 degrees to radians before doing the tan. You can confirm this in windows calculator by setting the units to RAD and doing a tan of 45. Hey presto it gives you 1.619 :mrgreen:

commented: Nice Response +1

thanks mark
i was trying to turn tan 45=1.6 radians and then convert to degrees the book i have does not make the fact you have to turn say 45 degrees into (radians first) then do tan command that clear.

Nice Response there mnemtsas, and should you need any further information regarding Tan (or other commands):

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.