two questions on GMP & C float
Sylvain Pion
Sylvain.Pion at sophia.inria.fr
Sat May 16 10:39:58 CEST 2009
Vojtěch Bubník a écrit :
> We are using GMP extensively for our geometric calculations like intersection lines between two 3d meshes etc. I am combining boost interval arithmetics with GMP to speed up predicates. That works really well. The interval arithmetics library is switching FPU rounding mode down. Does GMP use FPU or may I leave rounding mode set to "down" for the interval arithmetics library to work even during calls to GMP?
>
> Another question. If I know beforehand that the floats I am converting to mpq have some right mantissa bits cleared, will the mpq numbers be faster? Will the mpq representation use less bits? Will it help, if I write my own conversion function from float with limited mantissa to mpq?
In the case of a float, there is a big chance that lots of zeros will end
up in the denominator or the numerator, because one of them will have
a large power of 2 factor. Just consider 3.1415 as mpq.
I have the same application as Vojtěch, geometric predicates, which are
usually signs of polynomial expressions with machine floats as input.
The ideal way to compute these exactly is IMO to use MPFR instead of mpq_t.
Of course, once you use a division, you will need a rational type, so MPFR
is not enough, but maintaining a quotient of 2 "exact" MPFR will at least
compress the zeroes, which an mpq does not.
This is why I recently raised on the MPFR list the idea to add functions
dedicated to exact "polynomial" operations to MPFR (not that those are
hard to implement outside MPFR, of course).
--
Sylvain Pion
INRIA Sophia-Antipolis
Geometrica Project-Team
CGAL, http://cgal.org/
More information about the gmp-discuss
mailing list