1
$\begingroup$

In simple precision format, the largest possible positive number is

$A = 0 ~~~ 11111110 ~~~ 111\ldots 111$

Its predecessor is

$B = 0 ~~~ 11111110 ~~~ 111 \ldots 110$

But what is the absolute difference (in decimal) between these?

Appealing to scientific notation,

$A = 1.(2^{22}+2^{23}+\ldots + 2 + 1) \times 2^{2^{7}+2^{6} + \ldots + 2 - 127}$

and

$B = 1.(2^{22}+2^{23}+\ldots + 2 + 0) \times 2^{2^{7}+2^{6} +\ldots + 2 - 127}$

So they have only a difference of one point in the last decimal digit. The exponent tells us there are $2^{7} + \ldots + 2 - 127$ such decimal points. Let $e$ denote that quantity. Is it correct to say the difference is

$$0.\overbrace{000\ldots 000}^{e \text{ times}}1$$

or am I missing something?

$\endgroup$
3
  • $\begingroup$ I think your exponent $e$ for the scientific notations of $A,B$ should instead be $$e = 2^7+2^6+\cdots +2+\color{red}{0\cdot} 1 - 127 = 1111\ 1110_2 -127 = 127$$, not your $2^{7} + \ldots + 2 + 1 - 127$. $\endgroup$
    – peterwhy
    Commented Nov 10, 2023 at 17:25
  • $\begingroup$ @peterwhy You are correct, thanks for pointing that out. But are you implying that the answer is correct except but from that mistake in computing $e$? Namely, is the answer $0.000 \times 0001$ with $e$ decimal zeros, assuming $e$ is the correct value? $\endgroup$
    – lafinur
    Commented Nov 10, 2023 at 17:45
  • $\begingroup$ @peterwhy You are also correct, thanks. I'll edit that $\endgroup$
    – lafinur
    Commented Nov 10, 2023 at 17:45

2 Answers 2

1
$\begingroup$

Based on single-precision floating-point format:

Writing $A$ and $B$ in more standard notations,

$$\begin{align*} A &= 1.(2^{22}+2^{21}+\ldots + 2 + 1) \times 2^{e}\\ &= \left[1+2^{-23}\left(2^{22}+2^{21}+\ldots + 2 + 1\right)\right]\times 2^e\\ B &= \left[1+2^{-23}\left(2^{22}+2^{21}+\ldots + 2 + 0\cdot 1\right)\right]\times 2^e\\ \end{align*}$$

where the exponent $e$ is $$\begin{align*} e &= 1111\,1110_2 -127\\ &= 2^7+2^6+\cdots +2+\color{red}{0\cdot} 1 - 127\\ &= 127 \end{align*}$$

Then the difference $A-B$ would be

$$\begin{align*} A -B &= 2^{-23}\times 2^e\\ &= 2^{-23}\times 2^{127}\\ &= 2^{104}\\ &= 20282409603651670423947251286016 \end{align*}$$

$\endgroup$
1
  • 1
    $\begingroup$ That makes total sense. Thanks. $\endgroup$
    – lafinur
    Commented Nov 10, 2023 at 18:38
0
$\begingroup$

There is an 11 bit exponent field. Finite numbers have an exponent field that is not the largest possible, so the exponent field of a finite number is at most 2048-2. The number 1 has an exponent field where all bits but the highest are set, so the exponent field is 1023. The largest number has an exponent of 2046-1023, so it is at least $2^{1023}$.

The mantissa has 52 bits plus the explicit leading bit, so the last mantissa bit has a value of a large number is $2^{1023-52} = 2^{971}$.

With single precision you have 8 exponent and 23 mantissa bits, so the answer is $2^{127-23} = 2^{104}$, and for extended precision 15 and 63 bits) it is $2^{16383-63} = 2^{16320}$.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .