How to compute the successor to a given floating point number

51 Views Asked by At

Let $F$ the set of all floating point number $n2^e$ such that $ -2^{53} < n < 2^{53}$ and $−1074 \leq e \leq 970$. Let $F^* = F - \{\max(F)\}$

I assume $F$ not to be dense, and therefore there must be a function $succ \left| \begin{array}{ll} F^*&\rightarrow F \\ f&\mapsto \min \{ g \in F, g>f\} \end{array} \right.$ to find "the very next" floating point number.

How does one compute $succ(f)$ ?

1

There are 1 best solutions below

1
On

During the following, we will need to store values in the range $-2^{54}+2,\ldots, 2^{54}-1$ in $n$ and values from the range $-1127,\ldots ,970$ in $e$.

  • First handle special cases involving zero as input or output:
  1. If $n=0$, return $1\cdot 2^{-1074}$
  2. If $n=-1$ and $e=-1074$, return any representation of $0$ (e.g., $0\cdot 2^{42}$)
  • Now normalize to a definitely too long mantissa
  1. While $|n|<2^{53}$, set $n\leftarrow 2n$ and $e\leftarrow e-1$.
  • Advance to something definitely bigger (though not representable)
  1. Set $n\leftarrow n+1$
  • Work towards valid representations without making the value smaller
  1. While $|n|\ge 2^{53}$ or $e<-1074$, set $n\leftarrow \lfloor \frac {n+1}2\rfloor$ and $e\leftarrow e+1$