90 degrees is approximately 1.5707963267948966...
radians. I say "approximately" because PI is a transcendental number, but in double-precision floating point values, we are limited to 64-bits. That means the resulting calculation will be off by some margin of error. That same error occurs again when you take the cosine (a transcendental function). The resulting value cannot be perfectly represented in double-precision, so you receive an approximation. The correct answer is zero. The answer you have is 0.00000000000000061230317691118863
, which is very close to zero.
If you were to do this math by hand, using 3.14
as the value of PI, you will get an answer that is close to, but not exactly, zero, for the same reason: you are using approximations. Using 3.1415926
will give you a closer answer, but that value of PI is still an approximation. The computer is using another approximation, one limited to 64-bits of precision, which comes out to roughly 16 digits of PI.
This issue will occur in any computing system that uses IEEE-754 floating point math. See Is floating point math broken? for more info.
Also take a look at this blog post, which goes into greater detail in how PI is represented in computers.