# math confusion

I know i’ve been feeling a little ill lately, but this is unbelievable,
So here’s my code

``````import direct.directbase.DirectStart
import math

angle = 45
print angle
print math.tan(angle)

sqme = 3
print sqme
print 3^2

run()``````

Here’s the output

Now, why isn’t the tangent of 45 = 1?
And why isn’t the atan of 1 = 45?
My brain hurts…

Am I missing some really fundamentals about python, or is this something in panda?

Python is 2.6.2
Panda is 1.6.2

Looks like ppython is maybe 32 bit (2.6.1)
This is on a macbook os 10.6.2, 64 bit.
I guess that could be it…
Everything else (tuts and prior code) runs using system python, however…

Thanks

^ isn’t power in Python. Maybe it’s a bit-wise operator? (3^2 is 3 AND 2?) You need to use math.pow(x,y) to do powers.

Also, I am reasonably sure the math functions in Python work in radians, not degrees.

3**2

FenrirWolf and ynjh_jo are abslutely correct. python uses radians by default. whenever you’r in doubt what a function takes as input simply use pythons help() call.
for example

``````import math
help(math.tan)``````

would give this result

``````Help on built-in function tan in module math:

tan(...)
tan(x)

Return the tangent of x (measured in radians)``````
``angle_in_degrees=math.degrees(angel_in_radians)``

^ means bitwise-XOR