计算中
123456789 (1 110 1011 0111 1001 1010 0010 101)
+20 ( 10 100)
C中的结果是123456816(1 110 1011 0111 1001 1010 0110 000)我发现它似乎是四舍五入的,但在计算中
123456785 (1 110 1011 0111 1001 1010 0010 001)
+20 ( 10 100)
(结果是123456800)在这一点上,它看起来像是四舍五入,而两者加在一起看起来像是四舍五入
但
123456809 (1 110 1011 0111 1001 1010 0101 001)
再说一次,123456808 (1 110 1011 0111 1001 1010 0101 000)
没有意义
I tried to find the answer on Google and summed up the netizens' opinions were rounded nearby, 但 it still did not match the above results, so I think there may be some details I do not know, so I hope you can help me to figure out this problem
添加代码以演示:
#include <stdio.h>
int main(void) {
float x = 123456789.f;
float y = 20.f;
long m = 123456789L;
long n = 20L;
printf("As Floats, sum is: %0.1f\n", x+y);
printf("As Longs, sum is: %ld\n", m + n);
return 0;
}
输出
As Floats, sum is: 123456816.0
As Longs, sum is: 123456809