I’m using C for CUDA on 3.0 computing capability and have to use
built-in logarithm function of double precision. I found that for
that purpose I should use double log(double x) function (documentation).
But, if I pass a really small number within double precision scope
(e.g. double x = 6.73E-42),
log(x) function returns -Infinity. In Java Math.log() function for the same
value returns -94.802. Is this a bug within CUDA math library or am I getting something wrong?
EDIT:
Here’s the code I’m using in the kernel function
#include "math.h"
extern "C"
__global__ void smallLog(double* in, int n)
{
int i = blockIdx.x * blockDim.x + threadIdx.x;
if (i<n){
double x = in[i];
in[i] = log(x);
}
}
Make sure you are compiling for compute capability 3.0 (
nvcc -arch sm_30).By default, nvcc compiles for compute capability 1.0, which is single precision only and (as others have pointed out already) 6.73E-42 is zero in single precision and log(0) = -Infinity.