I have a strange problem with the standard cos function of cmath/math.h. Apparently under some circumstances it returns a wrong or simply undefined value.
#i
cos expects radians, you are giving it degrees. Multiply your input value by 3.14159/180, and you will get the right answer.