Using fractions instead of floats

mensanator at mensanator at
Wed Oct 3 06:53:22 CEST 2007

On Oct 2, 10:12?pm, "Gabriel Genellina" <gagsl-... at>
> En Tue, 02 Oct 2007 01:59:35 -0300, mensana... at  
> <mensana... at> escribi :
> > How does gmpy make the conversion from float to rational?
> Well, you know, these days valuable software usually comes with something  
> people call "documentation". Incomprehensible documents in strange formats  
> talking about esoteric stuff that nobody is able to read (as if someone  
> wanted to actually read them!).
> Hidden in the land of Mordor where the shadows lie, there is an ancient  
> scroll -a long time forgotten by mankind- where you can read terrible  
> things like this:
> "If an mpf or float argument is passed, the
> mpq is built from it with an 'optimal' approach based on a
> Stern-Brocot tree." <>
> On the motivation for doing such evil things, you can read the explanation  
> given centuries ago by its creator, by then the High Wizard Alessandro:
> "[The algorithm tries] to convert floats to rationals
> giving the smallest denominator compatible with the hypothesis that
> the float is precise to N bits [...] usually DBL_MANT_BITS [...] normally  
> 53 today"
> <>

The best place to hide something is in the
documentation. Which I have read often, but
that's one of the places where my eyes glaze

Thanks anyway. And to Robert Kern also.

> --
> Gabriel Genellina

More information about the Python-list mailing list