Mathf.Sin() & Mathf.Cos()

hi

i've got some weird response from the unity engine with some basic instruction :

tmp1 = 90 * Mathf.Deg2Rad; //response : 1.570769 correct!

tmp2 = Mathf.Cos(tmp1); //-4.371139E-08

print(Mathf.Rad2Deg * tmp2 );//-2.504478E-06

MathF.Cos have a radian as a parameter & return a radian value, after conversion to degre again shouldn't the Cosin of 90 be 0 ??

thanks :)

PS: (i'm sorry if its caused by a lake of knowledge from my part)

That's about as accurate as you can get while using floats for the first part of the equation.

The same equation using doubles instead:

Math.Cos((Math.PI / 180) * 90)

gives 6.12303176911189E-17 as a result, which is much closer to 0, but still not there

Either way - it's generally close enough for most unimportant calculations (especially if you're not storing the results), but if you need higher precision, go with the System.Math class instead and cast to float at the last possible second if you need to push the values into the unity API