jrtapsell jrtapsell - 3 years ago 155
Java Question

Is every double value rational?

Is every double a rational number (Excluding the special values [Infinity, -Infinity, NaN])? I am leaning towards saying yes, based on the following logic:


  • The mantissa has a value that can be represented as a decimal, which can be the numerator.

  • The exponent can be converted to a denominator, so that the result is scaled up and down as required.



Is this logic correct, and if not, what is wrong with it, and are there counterexamples which prove double values can be irrational?

Neo Neo
Answer Source

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).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download