XMP, Krita, KFileMetaInfo and Strigi
Jos van den Oever
jvdoever at gmail.com
Fri Jun 22 22:36:41 BST 2007
2007/6/22, Tobias G. Pfeiffer <tgpfeiffer at web.de>:
> On Friday 22 June 2007, 19:09, Jos van den Oever wrote:
> > 2007/6/22, Cyrille Berger <cberger at cberger.net>:
> > > > > - it lacks some important types like rationals
> > > >
> > > > a double is not a rational? QVariant::Double
> > >
> > > Yes it is, but a rational isn't a double, it's a division between two
> > > integers.
> > > For instance, there is no double representation of the rational 2 / 3
> > > (0.66666666666666666666666666666666 is just an approximation, even if the
> > > mathematical theory says that 0.666 followed only by 6 is equal to 2 / 3,
> > > but there is no way to represent such a thing in double, 2/3 is
> > > represented by 0.666..67 in a double anyway).
> >
> > It is very simple and not expensive to find a nice rational from a
> > double.
>
> What do you mean by "not expensive"? And what by "nice"? For every number that
> is stored as a double, there are infinitely many rational numbers that give
> that result. With both numerator and denominator being represented by a
> finite number of bits, you end up with a finite number of possible
> combinations, yeehaw. Now you don't even want to find a rational that has the
> same value as this double, but something "nice" that has a *similar* value as
> the given double. (Funny: look at 1.001002004008016032064128256, which might
> look very constructed, with powers of 2, but is actually the result of
> 999/998, continuing with digits 513 = 512 + 001024 etc.) -- Maybe this is a
> bit academic, but it seems to me as if storing a pair of integers is waaaay
> less problematic than trying to recreate such a representation from a double.
It is _very_ academic. In the graphic world the number of denominators
is really limited and all are smaller than 1000. So
double d;
int den = 0;
int nom = 0;
while (den++ < 1000) {
nom = round(den*d);
double error = abs(1 - nom / d / den);
if (error < 0.01) break;
}
if (den == 1001) {
// bad luck
}
is perfectly acceptable for many purposes and usually, a set fixed of
denominators is know, making it even easier.
Note that this algorithm is horrible inefficient, but still quite
cheap for gui purposes.
Cheers,
Jos
More information about the kde-core-devel
mailing list