idk if this is normal or not, i mean, it sure is close to 0, but is isn't 0 .

This is normal - things like cos are held as floating point numbers and computers are usually unable to 100% accurately represent them.

We normally don't notice this happening except in cases like this where us humans know what the answer should 100% be

ok

That's not a bug, that's how computers compute numbers. This also happens with tan(90) reporting a huge finite number rather than an Infinity.

Try adding 0.2 + 0.1

See how the resault is 0.3 0… 4? That’s because computers can’t handle math to full accuracy

That’s more because infinity isn’t a number so the equation used to calculate it will just return the highest possible value the computer can comprehens

Actually, according to the IEEE-754 standard (which ~~most~~ *all* modern computers use), Infinity, -Infinity, and NaN have binary representations, like all other numbers.

This video helps show how this also affects all numbers at large distances.

Actually, I believe that the issue here isn't in computing the cosine itself, but rather in the fact that the underlying JS trig functions use angles in radians, and the conversion from 90° to 𝜋/2 radians isn't precise (because 𝜋 is irrational). I asked Prof. Kahan about this when I was working on Berkeley Logo, and he told me the official right thing is to get the angle in degrees into the range [0, 45], which may involve interchanging functions sin↔︎cos and may involve remembering to change the sign of the result once it's computed, and *then* multiplying by 𝜋/180, and then calling the (maybe changed) function. In this example, instead of computing cos 90°, what we *should* do is compute sin 0°, which will indeed give an exact zero answer.