Ilya Zakharevich on Thu, 11 Jul 2024 09:36:54 +0200


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

Major problems with bitprecision()


When dealing with approximate calculations, one can get a certain
approximation to “the error” of the number returned from a PARI
function by doing
  exponent(x) - bitprecision(x);
However, this fails spectacularly when the output is 0.

Moreover, I could find it documented in
  ??_<_
  ??_==_
that PARI thinks this:
  (00:24) gp > my(d=(1.-1.)*2^bitprecision(1.)); d
  %4039 = 0.E1
  (00:07) gp > my(d=(1.-1.)*2^bitprecision(1.)); d==1
  %4027 = 1
  (00:22) gp > my(d=(1.-1.)*2^bitprecision(1.)); d<1
  %4037 = 0
  (00:23) gp > my(d=(1.-1.)*2^bitprecision(1.)); exponent(d)-bitprecision(d)
  %4038 = -63
  (00:27) gp > my(d=(1.-1.)*2^bitprecision(1.)); exponent(d)
  %4044 = 1
  (00:29) gp > my(d=(1.-1.)*2^bitprecision(1.)); d<2
  %4045 = 0
  (00:33) gp > my(d=(1.-1.)*2^bitprecision(1.)); d<4
  %4046 = 1
  (00:33) gp > my(d=(1.-1.)*2^bitprecision(1.)); d==3
  %4047 = 1

Is there a way to work around this?  From the output above, it seems
that PARI knows what is “the correct value” of
  exponent(d) - bitprecision(d),
(as -1) — but the output is 63…

Thanks,
Ilya