Karim BELABAS on Sun, 13 Oct 2002 18:29:18 +0200 (MEST)

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: bug in addrr

On Sat, 12 Oct 2002, Ilya Zakharevich wrote:
> On Tue, Oct 01, 2002 at 05:05:27PM +0200, Karim BELABAS wrote:
> > 3) switching to base 2^BITS_IN_LONG exponents would enable us to reuse the
> > integer multiplication code for floating point operations [ currently, they
> > are disjoint sets of routines ]. In particular fast multiplication would be
> > enabled at last for t_REALs.
> Note one shortcoming of this scheme: currently, to convert a
> float/double etc. to a t_REAL without a loss of precision, one can
> calculate in advance how many words one needs.  With this change one
> needs to inspect the exponent first.  This may introduce many subtle bugs...

Hadn't thought of that.

Currently dbltor(x) has length DEFAULTPREC, unless x is 0. (length 2),
which means 64 bits of precision (while the input had only 53). For most
values of the exponent (only 12 residue classes modulo BITS_IN_LONG are taken
care of by the extra 11 bits), it will be necessary to add an extra word.

So dbltor(x) would have length 2, DEFAULTPREC, or DEFAULTPREC+1, depending on
the operand. The only serious problem  I can see
with this is things like

  x = dbltor(f); ...; affrr(y, x)

But this kind of code is broken anyway [if f = 0...]. It's much better to use
  x = dbltor(f); ... ;
  z = cgetr(DEFAULTPREC);
  affrr(y, z);

[ possibly doing computations with one _more_ word of precision than was
intended is not a serious problem. One word _less_ would be more annoying. ]

Karim Belabas                    Tel: (+33) (0)1 69 15 57 48
Dép. de Mathematiques, Bat. 425  Fax: (+33) (0)1 69 15 60 19
Université Paris-Sud             Email: Karim.Belabas@math.u-psud.fr
F-91405 Orsay (France)           http://www.math.u-psud.fr/~belabas/
PARI/GP Home Page: http://www.parigp-home.de/