float和unsigned char间的强制转换出现的问题:
float f = 0.040;
f = f*200;unsigned short d = (unsigned short)(f);
printf("test float:%d\n",d);
f =0.040;
d = (unsigned short)(f*200);
printf("test float:%d\n",d);
结果是7,8.这个恐怕解释还得继续回去看基础吧,印象里好像记得有0.999999的说法,起码我一时间还不知道。
float f = 0.041;
f = f*200;unsigned short d = (unsigned short)(f);
printf("test float:%d\n",d);
f =0.041;
d = (unsigned short)(f*200);
printf("test float:%d\n",d);
戏剧化出现了,0.041正常,取整很正常,结果8,8。