I don’t think this is possible, hence I decided to ask here to see as googling around hasn’t returned any results that hint that I can do so.
Especially after reading this:
Can doubles be used to represent a 64 bit number without loss of precision
Though my numbers can be held in 32bit as the example below shows.
But is there any way in MATLAB to convert a double precision value to single without loosing information?
e.g. in MATLAB
> a = 103364148
a =
103364148
> single(a)
ans =
103364144
Or maybe there is another way in another language, e.g. Python?
I’m working with GPUMat where I can only use GPUSingle, so I’m trying to find a way to work with stuff that is double to MATLAB in single to the GPU.
Thanks,
A single can hold integer numbers up to 2^24 (16,777,216) without loss of precision – some bits are required for the sign and the exponent .
In other words, no, there is no way that you can make a number larger than 2^24 fit into a single without error (note that it can hold some larger numbers, as long as they can be written as the product of a number smaller 2^24 and some power of 2).
However, are you sure you need that kind of precision for your calculations? As long as all your integers are less than 2^24, you should be fine.