0
$\begingroup$

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?

$\endgroup$
3
  • 1
    $\begingroup$ 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. $\endgroup$
    – plop
    Nov 11, 2020 at 19:32
  • $\begingroup$ @plop What's an example of where the sums are not associative/distributive? $\endgroup$
    – Greg
    Nov 11, 2020 at 19:40
  • 2
    $\begingroup$ 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. $\endgroup$
    – plop
    Nov 11, 2020 at 19:49

2 Answers 2

1
$\begingroup$

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}$.

$\endgroup$
0
$\begingroup$

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

Indeed, between any two numbers $a<b$, 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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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