printf ("%d", 0.0625) 打印零,而附近的值(例如 0.0624)打印出您所期望的荒谬数字,为什么 0.0625 不同?
printf ("%d", 0.0625) prints a zero while nearby values such as 0.0624 print absurd numbers as you would expect, why is 0.0625 different?
我还注意到 0.0625 的倍数(例如 1.25)一直为零,但我找不到解释
根据 CostantinoGrana
"Do you know how IEEE 754 works? The numbers which you say "give 0"
are multiples of a not too negative negative power of 2. So when you
store them in little endian, the 32 less significant bits, that are
all 0, are the first thing you find in memory as int. Your int is 32
bits wide, thus 0."
我还注意到 0.0625 的倍数(例如 1.25)一直为零,但我找不到解释
根据 CostantinoGrana
"Do you know how IEEE 754 works? The numbers which you say "give 0" are multiples of a not too negative negative power of 2. So when you store them in little endian, the 32 less significant bits, that are all 0, are the first thing you find in memory as int. Your int is 32 bits wide, thus 0."