This function returns 1.22460635382238E-16 for Math.PI, which should be 0. Math.Cos has a bug too. Returns 1.22460635382238E-16 for Math.PI/2, instead of 0. And the Math.Tan is ***ed up too. It returns 1.63317787283838E+16 for Math.PI/2 instead of double.NaN or infinity. Be carefull when using these functions.