Current floating point (ANSI C float, double) allow to represent an approximation of a real number.
Is there any way to represent real numbers without errors?
Here's an idea I had, which is anything but perfect.
For example, 1/3 is 0.33333333...(base 10) or o.01010101...(base 2), but also 0.1(base 3)
Is it a good idea to implement this "structure":
base, mantissa, exponent
so 1/3 could be 3^-1
{[11] = base 3, [1.0] mantissa, [-1] exponent}
Any other ideas?
Asked By : Ignus
Answered By : jmite
It all depends what you want to do.
For example, what you show is a great way of representing rational numbers. But it still can't represent something like $\pi$ or $e$ perfectly.
In fact, many languages such as Haskell and Scheme have built in support for rational numbers, storing them in the form $\frac{a}{b}$ where $a,b$ are integers.
The main reason that these aren't widely used is performance. Floating point numbers are a bit imprecise, but their operations are implemented in hardware. Your proposed system allows for greater precision, but requires several steps to implement, as opposed to a single operation that can be performed in hardware.
It's known that some real numbers are uncomputable, such as the halting numbers. There is no algorithm enumerating its digits, unlike $\pi$, where we can calculate the $n$th digit as long as we wait long enough.
If you want real precision for things irrational or transcendental numbers, you'd likely need to use some sort of system of symbolic algebra, then get a final answer in symbolic form, which you could approximate to any number of digits. However, because of the undecidability problems outlined above, this approach is necessarily limited. It is still good for things like approximating integrals or infinite series.
Best Answer from StackOverflow
Question Source : http://cs.stackexchange.com/questions/28347
0 comments:
Post a Comment
Let us know your responses and feedback