It seems that the problem with the higher OP level is "try sin (x2 * M_PI / 180) == 0, but it does not work (probably because it is close to 0, but not 0)" - this is the goal to take the sine of x as expressed in degrees.
Instead of x%180 , which is a problem if x is a floating point, the idea is to first reduce the sin/cos argument to a range of 90 degrees before converting to radians. No need to give up some accuracy when comparing EPSILON.
See C ++ Sin and Cos for the exact value for many cases of n*90 degrees and other improved accuracy.
source share