Why is 0.1f the last binary bit rounded to 1?

I am listening to an operating system course in college, and we recently learned how floating point numbers are represented in memory.

Our homework is devoted to floatmanually converting floating-point numbers ( s) into their binary representations.

eg. 200,0234375would give 01000011010010000000011000000000after a long conversion process.

One question is about how 0.1f will be represented in memory. So I did the whole conversion process, and I ended up with this:

00111101110011001100110011001100

With what we have learned so far, this is the correct answer to the question (I asked the teacher).

But in the next question, we will be asked to check the answer with the program to see the actual binary representation of 0.1f. The real view is this:

00111101110011001100110011001101

(Pay attention to the last bit)

Then we will be asked to find out why this is happening.

I noticed a periodic one 0011when converting the number, and since the next bit after the final one 0will be 1, I would suggest that the computer will bypass this final one 0  before 1, which explains the difference.

So what I want to know, right? Is the computer rounding the last bit based on the next bit when 23 bits of the mantissa are used?

This is homework, so if you could just lead me to an answer, if I am wrong, I would appreciate it.

Also, I couldn’t find the answer to my question on Google for keywords I could think of. Forgive me if this is a duplicate.

+5
4

, , 23 ?

, . .

, 2/3 , 0.666 0.667? 0,667, .

+3

, , , , . IEEE . , .

+1

This will depend on your platform, the specific floating point equipment, and the specific settings of that equipment.

In particular, on x86 platforms, the specific behavior will depend on the contents of the FPU or SSE Control Word registers.

+1
source

There are several rounding modes.

You can read about it on wikipedia .

This is just a matter of implementation. C ++ has no standard for this.

+1
source

All Articles