Catch.Me Catch.Me - 1 year ago 200
Python Question

Python math.arctan() wrong result?

I am using python shell as a calculator, but I don't know why it can't handle -28/96 as an input for atan function:

math.atan wrong answer

My question is:
Why is this wrong?

Answer Source

Python is not handling it incorrectly. Python interprets "-28/96" as int divides int, so it returns the smallest following integer of "-28/96", namely, -1. What you need is "-28.0/96" and then python 2.7 will interpret the expression as float division and handle it as your wish.

Also, the same expression will return a double precise float in python 3, namely, "-0.2916666666666667".

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download