As most of them recognize, double → float suffers a loss of precision. This means that multiple double values can be matched with the same float value. But how do I go the other way? Given a normal (I don't care about extreme cases) float, how do I find the upper and lower double precision values that are still mapped to the same float?
Or, in code:
function boolean testInterval(float lowF, float highF, double queryD) { float queryF = (float) queryD; return (lowF <= queryF) && (queryF <= highF); }
and
function boolean testInterval(float lowF, float highF, double queryD) { double lowD = (double) lowF; double highD = (double) highF; return (lowD <= queryD) && (queryD <= highD); }
do not always give the same result. I am looking for two functions float-> double so that the second function returns the same result in the first place.
It might work, but it seems like a hack, not the right solution for me.
function boolean testIntervalHack(float lowF, float highF, double queryD) { double lowD = (double) lowF - Float.MIN_VALUE; double highD = (double) highF + Float.MIN_VALUE; return (lowD <= queryD) && (queryD <= highD); }
source share