More Issues With Floating Points

It is well-known that 1 3 \dfrac{1}{3} cannot be represented using a finite a finite decimal representation. 1 3 = 0.333 . \dfrac{1}{3} = 0.333 \ldots.

Neither can it be represented using a finite binary representation. 1 3 = 0.010101 2 \dfrac{1}{3} = 0.010101 \ldots _2

If we had just 24 bits to store the decimal part of this value, the closest rational number we could store in binary would be

5592405 16777216 \dfrac{5592405}{16777216}

What is the closest rational number to 0.1 0.1 that we could store using binary floating points with only 24 bits (assuming all the 24 bits are being used to store the fractional part of the value)?

If the value comes out to be a b \dfrac{a}{b} , where a a and b b are coprime positive integers , submit your as a + b a+b .

Assume that the point occurs before all the 24 bits. So, 111111111111111111111111 will be interpreted as 0.111111111111111111111111


The answer is 9227469.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

3 solutions

Arjen Vreugdenhil
Jul 26, 2016

Relevant wiki: Number Base - Problem Solving

One way to represent 0. 1 10 0.1_{10} in binary is by performing a long division. Another approach is to notice that 0.1 = 1 2 3 1 15 = 1 2 3 ( 1 16 + 1 256 + ) = k = 0 3 2 4 k 5 . 0.1 = \frac12\cdot 3\cdot \frac1{15} = \frac12\cdot 3\cdot \left(\frac1{16} + \frac1{256} + \cdots\right) = \sum_{k=0}^\infty 3\cdot 2^{-4k-5}. Either way, we find the repeated binary fraction

0.1 = 0.0001 1001 1001 1001 1001 1001 (1001 ...)

Because the 25th decimal is 1, rounding upward results in a smaller error than rounding downward:

0.1 ~ 0.0001 1001 1001 1001 1001 1010

This is the closest 24-decimal binary approximation of decimal 0.1. Writing this as a normal fraction, we get 11001100110011001101 0 2 2 24 = 1 677 722 16 777 216 = 838 861 8 388 608 , \frac{110011001100110011010_2}{2^{24}} = \frac{1\:677\:722}{16\:777\:216} = \frac{838\:861}{8\:388\:608}, so that the answer should be 9 227 469 \boxed{9\:227\:469} .

Exactly! And I was wondering why that was wrong.

A Former Brilliant Member - 4 years, 10 months ago

Aha! I made the mistake of assuming that the closest approximation has to be less than 0.1 0.1 and wound up finding 1677721 16777216 \frac{1677721}{16777216} . Silly!

Samrat Mukhopadhyay - 4 years, 9 months ago
Zee Ell
Jul 28, 2016

As 0.1 = 1677721.6 16777216 0.1 = \frac{1677721.6}{16777216} , therefore the closest integer numerator will be its rounded value, 1677722

Since the number formed of the last two digits (22, even) of the numerator is not divisible by 4 (therefore the numerator itself is neither) and the denominator ( 2 24 2^{24} ) has only the 2 as prime factor , therefore gcd(1677722,16777216)=2, meaning, that we can only simplify by 2 (in order to make the numerator and the denominator coprime).

Hence,

1677722 16777216 = 838861 8388608 \frac {1677722}{16777216} = \frac {838861}{8388608}

and the solution is

838861 + 8388608 = 9227469 838861 + 8388608 = \boxed {9227469} .

Edit: See Arjen's solution below

To go from 1 3 \frac{1}{3} to 0.33 0.33\ldots , one simply divides .

Similarly, we want to divide 1 101 0 2 \frac{1}{1010_2} in binary. That yields 0.0001100110011 2 0.0001100110011\ldots_2

In other words, we have Σ i = 1 3 2 4 i + 1 = 1 10 \Sigma^{\infty}_{i=1} \frac{3}{2^{4i + 1}} = \frac{1}{10}

If we had 24 bits, we would set represent it as 0.000110011001100110011001 which translates to 1677721 16777216 \frac{1677721}{16777216}

(This solution was originally marked correct. However, the answer was obtained by rounding down to the nearest 24-decimal binary value, while rounding up gives a closer approximation.)

Arjen Vreugdenhil - 4 years, 10 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...