Reputation: 7031
Is every double a rational number (Excluding the special values [Infinity, -Infinity, NaN])? I am leaning towards saying yes, based on the following logic:
Is this logic correct, and if not, what is wrong with it, and are there counterexamples which prove double values can be irrational?
Upvotes: 2
Views: 800
Reputation: 43709
You seem to be correct, doubles, at least IEEE 754 with base 2 are rational.
With IEEE 754 you have
x = s * m * b^e
s
is sign, m
is mantissa, b
is the base 2, e
is the exponent.
Since s
, m
, b
and e
are integer, x
must be rational.
Upvotes: 1
Reputation: 3786
This logic seems correct.
Computers can use only limited space, meaning they can only represent in memory rational numbers (When using double
format), as irrational numbers are composed of an infinite number of digits without repeating.
Coming to think about it, you can, however, store an executable code of a function that defines the number, rational or not, but this wouldn't work for every irrational and more importantly, isn't how double
works.
As for the special values, I don't think so. Infinity is not really a number, so I find it hard to define as rational or irrational. Same for NaN (Which is, by definition, not a number).
Upvotes: 3