Prev: "Why is it necessary to classify data according to its type in computer programming?"
Next: The syntax of C (note: homework task)
From: Pascal J. Bourguignon on 9 Jul 2010 10:53 Paul N <gw7rib(a)aol.com> writes: > On 9 July, 13:14, blm...(a)myrealbox.com <blm...(a)myrealbox.com> wrote: >> In article <87y6dnexi1....(a)kuiper.lan.informatimago.com>, >> Pascal J. Bourguignon <p...(a)informatimago.com> wrote: >> >> > Paul N <gw7...(a)aol.com> writes: >> >> > > Incidentally, I would be a bit surprised if a language actually >> > > provided a type for real numbers. >> >> > This is not impossible, using the right representation. �Eg. continued >> > fractions. �There are libraries, that you could integrate like gmp in >> > a given language. >> >> Are there libraries that allow representing *all* real numbers, >> including the irrationals? �I'm trying to imagine how that could >> work .... ? > > As I understand it, for the majority of real numbers, it would take an > infinite amount of space just to store one number. Which is why I > expressed my doubts. On the other hand, if it's a number that you are > interested in, it's probably one of the tiny minority that *can* be > represented in a finite space. > > Of course, any computer using a fixed size for numbers can only store > a tiny minority of the integers and a tiny minority of the floating > point numbers, so we're used to getting half measures anyway. At this point, google and wikipedia would be useful. Theorem: For every real number a, there corresponds a unique continued fraction with value equal to a. This fraction is finite if a is rational and infinite if a is irrational. However, continued fractions still have nice properties. For most real numbers (those you're "interested" in), you can determine an algorithm to compute the numbers of the serie in order. And you can compute an approximation using these numbers of the serie in order. Therefore you don't need to store an infinite number of parameters, but you can just compute those you need, when you need them (ie. at display time). Otherwise, it's already a big improvement over floating points, for rational numbers. -- __Pascal Bourguignon__ http://www.informatimago.com/ |