You need to slightly increase your expectations - in order to Math.Cos(x)be truly equal to 0, you would need an inaccuracy in Cos(which, of course, will happen) or for x, in order to have an irrational value.
- Math.Cos, 0. :
if (Math.Abs(Math.Cos(x)) < 1e-15)
, 1e-15 - , , . ( tan, ...)