问题描述
我是Java的新手,想知道double to int如何工作?我理解,它很简单的长整型通过采取低32位,但双(64位)到int(32位)呢?那么从二进制的double中的那些64位是双精度浮点格式(Mantissa),那么如何在内部转换为int?
这些都记录在中
( T
是 int
时,第二步是不相关的) p>
在大多数情况下,我希望这是使用硬件支持实现 - 将浮点数转换为整数通常由CPU处理。
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 ?
It's all documented in section 5.1.3 of the JLS.
(The second step here is irrelevant, when T
is int
.)
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.
这篇关于如何在Java中双向int转换工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!