如何在Java中双向int转换工作

如何在Java中双向int转换工作

本文介绍了如何在Java中双向int转换工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是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转换工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 01:44