Bug about 64-bit integer division The result of 64-bit integer division is wrong in certain situatio

Following code is expected to output 0, but actually outputs 77 on my laptop. It has wasted me a lot of time to find out the problem.

#include

using namespace std;

device int dData[2];

void* cuda_get_symbol_adress(const char* Name)
{
void* Ptr;
cudaGetSymbolAddress(&Ptr, Name);
return Ptr;
}

device bool get(int X)
{
return X != 0;
}

global void test(int Mod)
{
dData[0] = 0;
if (get(blockIdx.x)) dData[1] = 0;
if ((int)(687194767360ll % Mod) < 0) dData[0] = 77; // HERE, note that Mod is positive
if (get(blockIdx.x)) dData[1] = 0;
}

int main()
{
test<<<1, 1>>>(3);
int Temp = 0;
cudaMemcpy(&Temp, cuda_get_symbol_adress(“dData”), 4, cudaMemcpyDeviceToHost);
printf(“Temp = %d\n”, Temp);
return 0;
}

OS: Windows XP3
CUDA Toolkit: 2.3
CUDA SDK: 2.3
Host Compiler: cl.exe of Visual C++ 2005
Video Card: Geforce 8400M GS

687194767360 is a 64-bit number… Cant fit in 32-bit… Are you aware of it?
I am not sure if CUDA handles them correctly