# What are the differences between the set of Real Numbers and the Java datatype float?

Besides the fact that the real numbers ℝ go on forever whereas the floats only go up to a certain point (Float.MAX_VALUE) in Java, what else could I compare between these two sets of numbers?

• The arithmetic operations are also not the same. Sum is not associative $a+(b+c)\neq (a+b)+c$, not distributive $a(b+c)\neq ab+ac$, etc. It contains elements that are not representations of any real number, like the nans. – plop Nov 11 '20 at 19:32
• @plop What's an example of where the sums are not associative/distributive? – Greg Nov 11 '20 at 19:40
• You can find examples in many places. For example, here it looks like there are some. The examples depend on the specific floating point version: length of the mantissa, exponent, rounding type etc. Maybe you would like to read this note. – plop Nov 11 '20 at 19:49

The set of double precision floating point numbers in Java has the following elements:

Integers from 1 to $$2^{53}-1$$, multiplied by $$2^e$$ for integers e in some fixed range (which I am too lazy to look up right now).

+Infinity and -Infinity

+NaN and -NaN

+0 and -0.

The last six are not real numbers (+0 and -0 are both similar, but not quite the same as the real number 0).

Real numbers which are not Java floating-point numbers are 0, those numbers that are either too large or too small, requiring an integer e outside the allowable range, those that are not integer multiples of a power of two, and those that are integer multiples of a power of two with an integer > $$2^{53}$$.

The most important difference is that there are infinitely many real numbers and only finitely many floats.

Indeed, between any two numbers $$a, the set $$\mathbb R \cap (a,b)$$ is uncountably infinite (countably if you intersect with $$\mathbb Q$$ instead).

That is not the case with the floats.

Furthermore, the floating point numbers are well-ordered, i.e. any set $$S$$ of floating point numbers has a smallest element, whereas that's not the case with the reals.