Hexadecimal Floating-Point,roundIng
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 o开发者_JS百科peration (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.
yeah, when you printf() a 9.1 number, you're going to get rounding.
if you don't want rounding, you could , zero out the lower bits.
your error seems to be thinking that rounding will occur for part of the number, but not the whole number.
also here in tennessee, we don't use the word, mantissa. But we do use the "fractional part"
精彩评论