Daniel Lemire's blog

, 5 min read

What is the ‘range’ of a number type?

8 thoughts on “What is the ‘range’ of a number type?”

  1. peng says:

    float numbers/ real numbers is much complicated than integers. the range of float needs to worry about more than upper and lower bound, but also minimum closet difference between any two consecutive float number.

  2. Thomas Müller Graf says:

    I find it weird that 0.0 1 is out of range (not rounded to 0), but 1.0 1 is not out of range, and rounded instead to 1. The round-trip behavior might also be weird for numbers very close to (but not exactly) 0.

    gcc 11.2 can parse 2.22507e-308, but a bit below that is out of range.

    1. Your comment did not come out right. There is a formatting issue.

      1. Thomas Müller Graf says:

        I find it weird that 0.0 (…400 times 0…) 1 is out of range (not rounded to 0), but 1.0 (…400 times 0…) 1 is not out of range, and rounded instead to 1.

        The round-trip behavior might also be weird for numbers very close to (but not exactly) 0: I’m wondering if it will always work as expected if a number is first converted to a string, and then parsed again.

        gcc 11.2 can parse 2.22507e-308, but a bit below that is out of range. This doesn’t match the bound you gave with of 4.94e-324.

  3. Nicolas says:

    It’s probably best to consider 64-bit floating point range to be from 1.1e-308 to 1.8e308, i.e. excluding denormal values. Including denormal numbers is problematic because of the loss of precision. Including numbers beyond that is pointless because they are not representable.

    1. Surely, you want to include the two zeros as well as the negative numbers?

      1. Nicolas says:

        Sure that would make sense.

  4. pomarides Vofo says:

    <>

    How infinity could be inclusive?

    just only going from the definition it is simply impossible.