-2
$\begingroup$

Someone told me this and I would be interested to know if it is true:

In the ieee 754 format approximately half of the positive numbers are in the interval [0, 1]

$\endgroup$
  • 4
    $\begingroup$ Did you try to solve the problem somehow yourself, by say looking at the mentioned format? $\endgroup$ – Juho May 4 at 19:02
  • $\begingroup$ You ask about a pointless bit of trivia. You should instead study the ieee754 floating point formats. $\endgroup$ – gnasher729 May 9 at 20:46
3
$\begingroup$

"Floating point" means a representation in which the position of the fraction indicator (the "point") in a number is allowed to take on a range of values, allowing the fixed-length representation of numbers with a wide range of magnitudes, all with the same (relative) precision. This is done by decomposing the number into two fixed-length fields: the significand (or "mantissa" [Note 1]) and the exponent. The significand is a fixed-point value (usually the fixed point immediately follows the first digit and the first digit is required to be non-zero); the exponent is an integer exponent of some representation-defined base.

A common manifestation in ordinary discourse is the use of so-called scientific representation, in which numbers are decomposed into the product of a fixed-point decimal fraction (with the decimal forced to come right after the first digit, as above) and an integer power of 10. So, for example, the number 299742958 would be written $2.99742958\times10^8$. (That's the speed of light in metres/second, by the way.) If I was working in an environment where I could only use six decimal digits of precision, I would approximate that to $2.99743\times10^8$. And so on. In ordinary discourse, it's not usual to limit the size of the exponent, mostly because numbers so large that the exponent would need to be limited don't come up that often, but typographical and practical considerations force us to write a googol as $10^{10^{100}}$ rather than writing out the exponent in full. In a strict fixed-length representation, it might well turn out to be impossible to represent a googol other than by saying "a number too large to represent", which we might abbreviate as "$\approx\infty$".

IEEE-754 defines several binary floating point formats which have similar characteristics, except that they are in base 2 rather than base 10. They differ slightly from the above in that:

  • one bit is reserved for the sign
  • since the significand is forced to start with a 1, that being the only binary digit other than 0, only the fraction part of the significand is actually present (this is not true of extended precision versions).

The exponent is signed, but it is not stored in 2's complement. Instead, it is stored as an unsigned number representing the exponent offset by some integer. But the offset is close to the middle of the possible range of values, so the effect is similar to 2's complement. Also, the largest and the smallest exponent values are reserved for other purposes. For example, a number with largest exponent value is either $\infty$ or a NaN, depending on whether or not the significand is all 0s. (Also note than IEEE 754 $\infty$ is really $\approx\infty$, as above.)

With all that behind us, let's look at how many positive values are in the range $[0, 1]$. (Since the representation has a separate sign bit, exactly half of the possible numbers are negative and the other half are positive, except that 0 can be represented either as a "positive 0" or a "negative 0". In IEEE754 both representations of zero are allowed and must be considered equal. Zero is one of the special values referred to above, in case you were curious.)

If we leave out the limits of this range, we can see that all numbers whose offset exponents are less than 0 are in the range. (There are actually two more numbers in the range -- the limits -- but that doesn't significantly affect the count.) If the number of possible negative offset exponents is roughly equal to the number of non-negative offset exponents, then the count of representable values in the range $[0, 1]$ will be roughly half of the count of representable positive values. And, indeed, IEEE-754 sets the offset close to the middle of the range. (The range of possible exponent values has an even number of possible values, so the precise middle is impossible.)

But that's not just a feature of IEEE-754. Pretty well any general-purpose floating-point representation, regardless of precision or base, is going to have the same characteristic. The only requirements are that the significand and exponent are represented separately as fixed-length fields, and that the representation of the exponent is roughly balanced between positive and negative values.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ Specialized FP formats can have bias. For example A-law / µ-law companding. $\endgroup$ – TEMLIB May 9 at 19:37
  • $\begingroup$ @temlib: of course. This applies only to most fo representations. (Added a qualifier) $\endgroup$ – rici May 9 at 19:40
  • $\begingroup$ µ-law is 3bits exponent and 4bits mantissa. $\endgroup$ – TEMLIB May 9 at 20:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.