I have at my disposal a 32-bit unsigned int produced by a uniform random number generator routine. I would like to convert this number to a float in the range [0,1].
Obviously this is most easily done by dividing the unsigned int by UINT_MAX, casting both to float before division. Unless I’m very mistaken, I think such a division will cost me a lot of precision and is therefore not ideal.
Since this action will be performed in openCL, I assume not to have double variables I could use intermediately.
Any ideas how I could generate the float in a better way?
Thanks in advance!
Tom
I don’t think so.
You only have 32 bits of precision available to you anyway, so casting to a (presumably 32-bit) float and back should be OK.
You will have the 32-bit quantization “error”, but that’s based on the original 32-bit data type, not the float.