I am new to Java, and wondering how does double to int cast work ? I understand that it’s simple for long to int by taking the low 32 bits, but what about double (64 bits) to int (32 bits) ? those 64 bits from double in binary is in Double-precision floating-point format (Mantissa), so how does it convert to int internally ?
Share
It’s all documented in section 5.1.3 of the JLS.
(The second step here is irrelevant, when
Tisint.)In most cases I’d expect this to be implemented using hardware support – converting floating point numbers to integers is something which is usually handled by CPUs.