将整数转换为浮点值Casting Integers to Floating-Point Values

ANSI 3.2.1.3 当一个整数转换为无法确切表示原始值的浮点数时的截断方向ANSI 3.2.1.3 The direction of truncation when an integral number is converted to a floating-point number that cannot exactly represent the original value

当一个整数转换为无法确切表示值的浮点值时,值将被舍入(向上或向下)到最接近的适当值。When an integral number is cast to a floating-point value that cannot exactly represent the value, the value is rounded (up or down) to the nearest suitable value.

例如,将 unsigned long(具有 32 位精度)转换为 float(尾数具有 23 位精度)会将该数字舍入到 256 的最接近倍数。For example, casting an unsigned long (with 32 bits of precision) to a float (whose mantissa has 23 bits of precision) rounds the number to the nearest multiple of 256. 介于 4,294,966,913 和 4,294,967,167 之间的所有 long 值都将舍入到 float 值 4,294,967,040。The long values 4,294,966,913 to 4,294,967,167 are all rounded to the float value 4,294,967,040.

另请参阅See Also

浮点数学Floating-Point Math