5
$\begingroup$

If I iterate over binary representations from 000...000 to 111...111, is there a significant transition at some point?

In the IEEE 754 float32 format, the position of the bits matters, where the most significant bit (MSB) is the sign bit:

sign (1) | exponent (8) | mantissa (23)

If I start iterating from 0, 1, 2, 3 in binary representation and convert each iteration to its float32 representation, I observe the smallest possible transition (or step) between consecutive float32 values, which is expected.

However, I am uncertain about what happens during larger iterations, specifically when the exponent and sign bits are affected.

So, for example, the binary of 100110..0001 might has big difference in the perspective of float32 like 1.222 to the25.2 if the binary is incremented.

So, my question is: at what points does incrementing a binary number result in a large difference in its corresponding float32 value?"

$\endgroup$
3
  • 3
    $\begingroup$ en.wikipedia.org/wiki/Subnormal_number reflects a significant change in representations, though not necessarily in absolute values. $\endgroup$ Commented Sep 10, 2024 at 20:05
  • 1
    $\begingroup$ I think there may be some confusion due to language barriers here. I believe that the question you're asking, based on your comments to answers, is "when does incrementing as if it's a normal int cause a floating-point increment that isn't one ulp?". If so, I think that's a pretty different question than the surface reading of your text here. $\endgroup$ Commented Sep 12, 2024 at 17:24
  • $\begingroup$ @DanielWagnet Yeah pardon me for bad English, but It's fine I also accepted the answers and understand what they mean. I was questioning this for IEEE754 encoding to quantum computing since quantum computing still in low level data representation. But I think I don't need IEEE754 in quantum computing because there are many encoding technique to represent float into qubit. $\endgroup$ Commented Sep 12, 2024 at 18:09

2 Answers 2

15
$\begingroup$

Incrementing 011111110111...111 to 011111111000...000 changes the float32 value from $\approx3{.}4\times10^{38}$ to +infinity, which is an infinite difference. Likewise with negative sign. (There are also transitions to/from NaNs, but for those the magnitude of the “difference” is meaningless, I’d say.)

The largest finite difference, $\approx2{.}028\times10^{31}$, occurs between any two consecutive numbers of the form (0/1)11111110... (with absolute values between $\approx1{.}7\times10^{38}$ and $\approx3{.}4\times10^{38}$).

$\endgroup$
5
  • $\begingroup$ 0|11111110|00000000000000000000000 (1.7014118e38) -> 0|11111110|00000000000000000000001 (1.701412e38) I don't think it's largest finite difference, looks like still smallest step for me. $\endgroup$ Commented Sep 10, 2024 at 10:29
  • 5
    $\begingroup$ Well, it is, whether you like it or not. The encoding is such that incrementing an integer representation of a finite positive real (except for the largest one) results in the next finite real, which only differs by one ulp. “I don’t think” is not an argument. $\endgroup$ Commented Sep 10, 2024 at 11:22
  • $\begingroup$ @MuhammadIkhwanPerwira I think you mean something different by "smallest step": a step to the next representable number so that no other floating point value comes in between. $\endgroup$ Commented Sep 10, 2024 at 18:05
  • $\begingroup$ @Bergi Yes, that's exactly what I mean. No other floating point value comes in between. Which mean that's the only one floating point with smallest step. $\endgroup$ Commented Sep 10, 2024 at 19:05
  • $\begingroup$ Actually my goal is to detect anomaly during incrementing in quantum computing. Like infinite difference NaN, -inf, inf that has been answered, in that case I make special exception for such binaries. Another anomaly is sign bit with another all bits are zero. +0 and -0 are considered same. $\endgroup$ Commented Sep 10, 2024 at 19:17
8
$\begingroup$

For all of the "normal" finite floating point numbers (those between 1.18*10^-38 and 3.40*10^38, or between -1.18*10^-38 and -3.40*10^38, for IEEE-754 binary32 floats), the behavior is very regular: the step between two successive floats is constant between any two powers of two, and doubles at each power of two.

That is:

  • For all of the floats in [0.5, 1), incrementing the binary representation by 1 will increase the floating-point value by 2^-24.
  • If a value is in [1, 2), incrementing its binary representation will increase it by 2^-23.
  • If a value is in [2, 4), incrementing its binary representation will increase it by 2^-22.
  • ...
  • If a value is between 2^23 and 2^24, incrementing its binary representation will increase it by 1.
  • et cetera, up to the largest finite value.

For the subnormals and zeroes (values between ±1.18*10^-38), it's also simple: the step is 2^-149 for all of them, and doesn't change at powers of two.

There are no unexpected "jumps" within the finite values. The largest finite values are adjacent to ±Inf, which in turn are adjacent to NaNs, but it doesn't make any sense to talk about the numerical difference between those.

As a special case, +0 (0x00000000) and -0 (0x80000000) are also adjacent to NaNs (0xFFFFFFFF and 0x7FFFFFFF, respectively).

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.