Вопрос

I have received a code line that's like entr -= normed_eigval * log(normed_eigval) / log(dim);

While normed_eigval stems from complexArray*, I know that dim is of type ptrdiff_t. When I try to compile the code using the MEX interface of MATLAB and Visual Studio 10 as compiler, I receive an error:

C2668: ambiguous call to overloaded function

telling me that log could either be long double, float or double.

I am using a 64-bit Windows machine. Can I solve this problem using a type cast? If yes, which type should I choose? I figure there's some possible problems under 64-bit Windows if size_t or ptrdiff_t are to be transformed into standard integer types...

Это было полезно?

Решение

Choose whichever one agrees with normed_eigval because that determines the numeric precision you're working with. You will be converting the ptrdiff_t integer into a floating-point value, then taking its logarithm.

Likely you can precompute the inverse of the logarithm, if you need it to go faster.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top