# How to compute the successor to a given floating point number

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)$$ ?

• this seems to be nearly the ieee double precision binary format. if packed into a uint64_t with 1 sign bit, 11 exponent bits, 52 mantissa bits, then for finite positive normalized numbers (with leading 1 mantissa bit implicit), I think you can just add 1 to the uint64_t - if the mantissa doesn't overflow, it's fine, if the mantissa overflows from (1).111.. to (10).000..., the overflow goes into the exponent and increases it by 1, also fine. the corresponding C library function for this operation is called nextafter() (alternatively nexttoward()) Oct 16, 2023 at 17:41
• @Claude Thank you for your interest in the question, I appreciate the help. You are right, this is supposedly the ieee 64 but floating point number definition more or less. Can you demonstrate that incrementing the exponent must give the smallest increase in the floating point space ? Indeed, why couldn't there be another number in F with a smaller $n$ and larger $e$ that could squeeze between $f$ and your answer (and vice versa)? Oct 16, 2023 at 17:53
• IEEE double normalized values have (implicit) leading 1 bit, so the fractional mantissa $m$ can be considered to be in $1 \le |m| < 2$. Denormalized values are smaller than the smallest normal number. Thus each number has a unique representation. Oct 28, 2023 at 16:04
• Your definition is not quite the same as IEEE double as $2n\times 2^{e-1}=n\times 2^e$ so representation is not unique, even if the set of representable values might be the same (I have not checked). Oct 28, 2023 at 16:10

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$$.
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}$$)
1. While $$|n|<2^{53}$$, set $$n\leftarrow 2n$$ and $$e\leftarrow e-1$$.
1. Set $$n\leftarrow n+1$$
1. While $$|n|\ge 2^{53}$$ or $$e<-1074$$, set $$n\leftarrow \lfloor \frac {n+1}2\rfloor$$ and $$e\leftarrow e+1$$