十六进制浮点,roundIng [英] Hexadecimal Floating-Point,roundIng

查看:194
本文介绍了十六进制浮点,roundIng的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试以下例子:

  printf(%9.1a,4488.09); //数字点后只能打印一个数字

4488.09 == 1 0001的二进制表示1000 1000.0001011100001010001111010111000010100011110101
应该变为0x1.1p + 12或0x1.2p + 12?

如果必须执行舍入操作二进制表示或1.18 + 13表示?如果它应该执行 ceil() - 8正好在十六进制范围的中间...

解决方案

除非将小数位数限制为太小,否则二进制总是可以毫无损失地转换为小数。如果尾数值类似于1.188170A3D70A4,并且您将printf()限制为只有1个小数位,则应该为尾数打印1.2。如果将其限制为2个小数位,则应该得到1.19。如果3,那么1.188。如果4,那么1.1881。等等。


I try the following example:

printf("%9.1a",4488.09); //Only one digits has to be printed after digital point

The binary representation of 4488.09 == 1 0001 1000 1000.0001011100001010001111010111000010100011110101 should become 0x1.1p+12or 0x1.2p+12 ?

I cant undrstand if the round operation (while printing) has to be performed for the binary representation or for the 1.18+13 representation?And if it should perform ceil() - the 8 is exactly in the middle of the hexadecimal range...

解决方案

Binary can always be converted to decimal without a loss, unless you restrict the number of decimal digits to a too small number. If the mantissa value is something like 1.188170A3D70A4 and you restrict printf() to only 1 fractional digit, you should get 1.2 printed for the mantissa. If you restrict it to 2 fractional digits, you should get 1.19. If 3, then 1.188. If 4, then 1.1881. And so on.

这篇关于十六进制浮点,roundIng的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆