I just trie to understand IEEE 754. So far I understand, that the binary code of a number like 200,1 is periodic, and as the mantissa has only 23 bits (float) it has to be chopped. But everybody is talking about "rounding" instead of chopping. I read, that you round the last bit, if the number is not representable. But why should a binary number not be representable...I dont get it. Could so give me an example please :)
Asked
Active
Viewed 74 times
0
-
1Possible duplicate of [Why can't decimal numbers be represented exactly in binary?](http://stackoverflow.com/questions/1089018/why-cant-decimal-numbers-be-represented-exactly-in-binary) – 200_success Nov 10 '15 at 20:56
-
No, I understand why they cant be represented exactly in binary. My Question is. Why do I need to round after I chopped that infinately long number after 23 Bits – Maxi Nov 10 '15 at 21:08
-
Can you clarify your question using the example 200.1 that you mentioned? – Yosef Weiner Nov 10 '15 at 21:19
-
1You round because it minimizes the deviation from the precise value. Its obvious that if the precise value is 1.95 and you need an int that 2 is a lot closer than 1, do you? – Durandal Nov 10 '15 at 21:20
-
@SkinnyJ 200.1 = 010000110100100000011001100110011001100110011... now because I only habe 23 Bits I have to chopp: 01000011010010000001100 – Maxi Nov 10 '15 at 21:28
-
But eg http://www.h-schmidt.net/FloatConverter/IEEE754.html says 01000011010010000001100110011010 – Maxi Nov 10 '15 at 21:31
-
It's not clear to me why you are chopping off after 23 bits instead of paying attention to enough bits after that to round. Is that where you're confused? – Louis Wasserman Nov 10 '15 at 22:09
-
@LouisWasserman as I can only save 23 of these bits in a 32bit float – Maxi Nov 10 '15 at 22:36
-
What is the actual situation you're trying to understand? If someone writes the number 200.1, you can temporarily store more bits than 23 while you're trying to compute the closest float to 200.1. Your _output_ has to be a 32 bit float, but you can compute more bits than that as part of the process. – Louis Wasserman Nov 10 '15 at 22:38
-
@LouisWasserman so is that what actually happens? – Maxi Nov 10 '15 at 22:48