Reputation: 2352
I would like to specify a set that exactly covers the number range for double / float.
For Integer
it's quite easy because they are all natural numbers from Integer.MIN_VALUE
to Integer.MAX_VALUE
so
INTEGER = { x e ℕ | x ≤ 2147483647x ≥ -2147483648 }
For double
and float
it's harder because of the precision of that data types
To ask for "a mathematical representation" may be a bit imprecise. So what do I need:
I'm looking for a definition that fits this pattern:
Double = { x e ℝ | x ≤ 2-1022x ≥ -2-1074{insert further conditions here} }
Upvotes: 2
Views: 138
Reputation: 41794
Without infinity and special values like NaN, the real values are actually rational numbers
Upvotes: 2
Reputation: 9086
Well, the extreme values are Double.MIN_VALUE
and Double.MAX_VALUE
. As computers are discreet entities and real number are continuous there are "holes" in this range.
The gory details are in IEEE 754.
Upvotes: 3
Reputation: 43738
Just to give you an idea and ignoring constants and some special cases (normalization, hidden one, gradual underflow, ... - you can work out the details), the representable numbers are basically
M * 2^E where MMIN <= M <= MMAX and EMIN <= E <= EMAX
This is by the way even a subset of the rational numbers. It is not possible to represent irrational numbers in this format.
On the other hand, there are also several values, that are not numbers at all.
Upvotes: 0