i have implemented two little programm and in both programms i have this lines
#define PI ((float)3.14159265358979323846264338327950288419716939937510)
float theta = -50.0; //
float phi = 0.0; //just for testing purpose set to 0
theta=theta*PI/180.0; /*radians*/
float result = cos(theta);
now the result in normal c on cpu is
result_cpu = 0.642787635
and in the cu file calculated on cpu (not in any kernel)
result_gpu = 0.642787576
in both programms i have included the math.h
any idears why this happens? because i need the values calculated with this result for my kernel and i think there should not be any difference between this two values.
cheers
[edit]
how can i select the math standard cos function in cu file if this is the problem
All floating point numbers (float, double) are only approximations of real numbers. What you got there are two different approximations, none “correct” in pure mathematical sense, but both good enough for most applications.
You mix float and double precision in your example. CUDA can only do float precision, not double. If you change the double precision “cos()” to the float precision “cosf()” I guess your results will be more close to each other.