I would like to create the Double whose value is closest to, but greater than, Float.MAX_VALUE.
I’ve just written a question similar to this but for Double and Long.MAX_VALUE, see here.
How can I repeat the conversion for Double and Float.MAX_VALUE using the standard Java 6 API?
My attempt is below, but is incorrect it seems:
Long longValue = Long.valueOf(Float.floatToIntBits(Float.MAX_VALUE));
Double value = Double.longBitsToDouble(Double.doubleToLongBits(longValue)+1);
if (value < -Float.MAX_VALUE || value > Float.MAX_VALUE) {
// Code here should execute but does not.
}
Sincere thanks.
It’s not only equivalent to the most efficient solution, but…it makes it pretty obvious what result you should expect.