What I’m trying to do is this:
I have an array of floating point values. These values need to be “continuous” (hence I can’t store integers instead), but I need to use them to index into another array.
In standard C I would do something like this:
(int) floor(value + 0.5f);
Converting 1.56 to 2, 1.04 to 1, etc. Allowing me to use them to index into an array.
In CUDA, however, the same (using floorf) doesn’t seem to provide the same results as standard C. Looking through the programming guide, I’ve also tried __float2int_rn (and _rz) as well as __float_as_int. Neither provided the same results either.
Any suggestions on how to mirror the functionality would be greatly appreciated!
Just to provide some further information, both results match up if I drop the addition of 0.5f in the floor function call:
However, as soon as I add in + 0.5f to both the C and CUDA code, it breaks. I’m not sure if I’m missing something in CUDA, or something fundamental to floating point numbers here…