Yes and no. Yes, because in an abstract sense, infinity is infinite (and, as I will explain below, for the purpose of most code floats, anyway).
No, however, because at the bit level the two infinities are different. The double is 64 bits in Java and the float is 32 bits in Java, so they trivially differ at the presentation level.
In Java, floating point numbers (floats and doubles) are represented using the IEEE 754 floating point, which is the standard pretty much everyone uses today. Each number is represented in binary form as a sign bit, plus a certain number of exponent bits, plus a certain number of mantissa bits (significant). In float or double, positive infinity is represented by the signed bit 0, exponential bits of just 1 and the mantissa bits of only 0. Negative infinity is represented in the same way, except for signed bit 1. Thus, infinity is represented in two very similar ways, but Due to the different number of bits of the exponent and the mantissa between floats and doublings, bit level patterns are different.
For the purpose of writing code, you can view them as one and the same. Whenever you use doubles and swim together, unless you explicitly specify otherwise, the float will automatically reset to double and the expression will double, so the infinity of the float "acts like" double infinity "for most practical purposes.
Adam mihalcin
source share