Python cos(90) and cos(270) not 0

Indeed, it is a very low number, awfully close to zero. Here's a great article which can help you understand the common challenges and pitfalls of floats: "What Every Computer Scientist Should Know About Floating-Point Arithmetic"


You are dealing with rounding errors, which are (mostly) unavoidable when working with floating point math (see the paper already linked by others to understand exactly what's going on).

In many cases you can reduce their impact (by performing the operations in "intelligent" order or reformulating your expressions in a more "floating point-friendly" way), but the simplest thing to do in your situation is to round the results to e.g. 6 decimal places and be happy with it. Surely you won't need more precision in positioning, and you'll get the results you expect for the "canonical" angles.