Python Forum

Full Version: Converting Angle to X and Y Values: 90/180/270 deg
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So I have a way to turn an angle into x and y values:
angle = math.radians(0)
y = math.cos(angle)
x = math.sin(angle)
print(x,y)
and it prints:
Output:
0.0 1.0
but then, I change they 0 to 90:
angle = math.radians(90)
y = math.cos(angle)
x = math.sin(angle)
print(x,y)
and would expect to have 1.0 0.0 as the output, but got this:
Output:
1.0 6.123233995736766e-17
which is a super miniscule number, but why isn't it 1.0 0.0?
and how can I make it right?
http://docs.python.org/tutorial/floatingpoint.html or
http://www.lahey.com/float.htm
Quote:how can I make it right?
Use Python's decimal module for more precision than a floating point.