[英]The precision of the natural logarithm is not correct in CLISP. What might be wrong?
[英]cuda double precision logarithm error
我使用C表示CUDA 3.0的计算能力,并且必须使用双精度的内置对数函数。 我发现为此我应该使用double log(double x)
函数( 文档 )。 但是,如果我在双精度范围内传递一个非常小的数字(例如, double x = 6.73E-42
),则log(x)
函数返回-Infinity
。 在Java Math.log()
函数中,相同的值返回-94.802
。 这是CUDA数学库中的错误还是我得错了?
编辑:这是我在内核函数中使用的代码
#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);
}
}
确保您正在编译计算能力3.0( nvcc -arch sm_30
)。
默认情况下,nvcc为计算能力1.0编译,这只是单精度而且(正如其他人已经指出的那样)6.73E-42在单精度中为零,log(0)= -Infinity。
对于你的问题,答案应该是-94.802。
尝试将log(6.73E-42)
拆分为
log(6.731E-20) + log(1E-22) = [(-44.145)+(-50.66)]=(-94.802)
或者,如果你想要,你可以分成更多的部分,最后添加。 很抱歉,我的设备不支持双精度。 这就是我能给出的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.