Question

I compute two numbers using a CPU and a GPU. They are both double precision floating point numbers. When I print them using printf I get:

CPU=11220648352037704534577864266910298593595406193008158076631751727790009102214012225556499863999825039525639767460911091800702910643896210872459798230329601182926117099298535084878987264.00000 GPU=-4.65287

using:

void print(const double *data1, const double *data2) {
    ...
    printf("CPU=%.5f\tGPU=%.5f\n", data1[k], data2[k]);
}

Which is way to many digits I would expect. Why do I get this? Do I overflow, underflow, corrupt memory? Please help.

Thanks.

Was it helpful?

Solution

You used the printf format %.5f. That means "print plain decimal digits all the way down to five places after the decimal." If you want scientific notation instead, which is more common with such large numbers, you should use %.5g, which means "print automatic format digits all the way down to five places after the decimal...or really four places in scientific notation."

Note that such huge numbers as you have are definitely within range for a double. There is nothing unusual about the value of the number in the code you have posted.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top