I've run into a problem which is that Math.cos doesn't return a value between -1 and 1 but rather returns the value 6.123233995736766 when I pass the value 1.5707963267948966 to it.
The whole operation I'm going through is as follows.
Actually, the result is
Math.cos(90 * Math.PI / 180) == 6.123233995736766e-17
e-17 here. The notation
eN after a number means "times 10N".
That means that the calculated number is actually 6.123233995736766 × 10-17, which is very actually a very small number and very close to the expected value 0.
The reason why there's a small difference here is that computers are really bad at computing functions such as sine and cosine exactly, so most of the time there will be a small (but negligible) difference between the computed value and the exact value.