genn icon indicating copy to clipboard operation
genn copied to clipboard

Overloaded C99 math functions for integer arguments

Open tnowotny opened this issue 3 years ago • 1 comments

In NVCC there is no overloaded function for, e.g., exp(a) if a is an integer variable or constant. This could lead to problems if users use integers in their models. A case in point is https://github.com/brian-team/brian2genn/issues/133 Suggested solution is to define overloaded functions for all math functions like so:

__host__ __device__ scalar exp(int x) {
    return exp((scalar) x);
}

for the CUDA backend. However, this would mean that there is a potential discrepancy for the CPU version, in which exp(a) for integer a resolves to double. We could therefore also add

scalar exp(int x) {
    return exp((scalar) x);
}

for the CPU backend.

tnowotny avatar Sep 08 '21 16:09 tnowotny

It will be a little more tricky for the CPU backend as these overloads will clash with the existing integer overloads but maybe they can be 'hidden' somehow..

neworderofjamie avatar Sep 08 '21 16:09 neworderofjamie