# How to get the same results of the trigonometric functions( double precision )

Hi,
Why do I get different results on OpenCL (nVidia GTX760) and the classic code CPU?
OpenCL:

``````#pragma OPENCL EXTENSION cl_khr_fp64 : enable
__kernel void keDistAzimStep(	__global double2 * da, __global double2 * coords )
{
int i = get_global_id(0);
double2 cp = radians( coords[i] );

double sin_sr2 = sin( cp.y );
double cos_sr2 = cos( cp.y );

da[i] = (double2)( sin_sr2, cos_sr2 );
}
``````

Delphi XE2 64bit:

``````procedure TestSinCos(index:integer);
var cp:TDVec2;
sin_sr2,cos_sr2 :double;
begin
sin_sr2 := sin( cp.y );
cos_sr2 := cos( cp.y );

FDA[index] := dvec2( sin_sr2, cos_sr2 );
end;
``````

Even on the primitive functions I get the difference 1.11022302462516e-16.
Is it possible to get the same result?

For what input value? Since doubles have 15 to 17 decimal digits of precision, your result is expected accuracy for a result was between (say) 0.1 and 1.0. A CPU might use 80 bit intermediate precision while a GPU is likely just 64 bits.

OpenCL requires that sine has a minimum accuracy of 4 ulp.
For example, if the expected result is 0.5, one ulp is 2^-53 = 1.11e-16. So the maximum admissible error is 4 ulp ~ 4.5e-16.

So the implementation of OpenCL you use is conformant.

You cannot expect the same result between two different devices because the trigonometric functions are not necessarily implemented in the same way.