我可以担任中文翻译,以下是翻译结果:
问题是,我们如何手动将它们相互转换?(我知道会丢失精度)。 将双精度转换为单精度只需要进行
我知道double是64位,float是32位:
浮点数:
1 bit for the sign
8 bits for the exponent
24 bits for the fraction
双精度浮点数:
1 bit for the sign
11 bits for the exponent
53 bits for the fraction / mantissa
问题是,我们如何手动将它们相互转换?(我知道会丢失精度)。 将双精度转换为单精度只需要进行
32位右移
吗?
将单精度转换为双精度只需要进行32位左移
吗?
float
转换为double
不会丢失精度。只有从double
到float
的转换才会有真正的问题。