Title: (2004-11-01 16:32:40) Paradise Rain (124059489) Main () {Float A, B; A = 123456.789E5; B = A 20; Printf ("% f", b);}
This is explained in this book:
When the program is running, the value of the output B is equal to A. The reason is that the value of A is more than 20, the theoretical value of A 20 should be 12345678920, and a real variable can only be guaranteed to be a valid number of 7 effective numbers, and the numbers behind are meaningless, not accurate. Represent this number. The values of the A and B for running procedures are 12345678848.000000, and you can see that the first 8 is accurate, the last few bits are inaccurate, and 20 adds 20 to the last few positions, it is meaningless. You should avoid adding a large number and a small number directly, otherwise it will "lose" small number. Similarly, the result of calculating 1.0 / 3 * 3 using the program is not equal to 1.
My question is: 12345678848.000000 How did this figure come?
Answer: (2004-11-01 19:43:32) Mmpire (23433725) In the IEEE floating point representation, a FLOAT number is stored in 32-bit storage, the specific assignment is: 31 bits: symbol bit 30-23 bits: Inditable bit 22 -0: Number, only 23 can be used to deposit (actually available 24-bit binary number, because the first one can always be omitted), and 33 digits after 12345678900, as follows: 10 1101 1111 1101 1100 0001 1100 0011 0100 Only 24 bits of its top 24, after calculation, 9 pins 10, from 10 1101 1111 1101 1100 0001 1100 0000 0000 Use Microsoft's own calculator, just 1234567884832 Float number of IEEE stored procedures ****************************************************** * 1234567890012345678920
10 1101 1111 1101 1100 0001 1100 0011 11001.01101 1100 0011 010010 1101 1111 1101 1100 0001 1100 0000 000033 Position 1 Remove 0 1101 1111 1101 1100 0001 1100 0011 0100 Control at 23 bits 0 1101 1111 1101 1100 0001 110 1101 1111 1101 1100 0001 11 Index plus 12733 127 = 16010100000
0 (1010 0000) 0110 1111 1110 1110 0000 11101010000 00110111 11101111 0000011150 37 F7 07 turned over: 07 F7 37 5010110111111110111000001111