jacques G on Tue, 18 Oct 2011 20:58:22 +0200


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

Parameters of floating-point arithmetic ?


Question 1: Do the two PARI/GP programs below (flpari, flparam) work correctly on 64-bit machines ?

Question 2: Will the fast GP-specific flpari() program work in future versions of PARI/GP ?

Thanks for any answers or other comments,

Jacques Gélinas, Ottawa, Canada


flpari(p=precision(1.)) = {
  local(w=#precision(1.,p));
  [2, w, w*=64/#precision(1.,18), 2.>>w];
}

addhelp(flpari,"flpari(p): parameters of p-decimal PARI/GP floating-point arithmetic"\
" [base, words, bits, machine epsilon]")

flparam() = {
  local( base = 2., mant = 8.^precision(1.) );

  while( (( mant + 1.   ) - mant) == 1.,  mant*=2. );

  while( (( mant + base ) - mant) != base, base+=1. );

  [ round(base), round( log(precision(mant,18)) / log(precision(base,18)) ), 2./mant ];
}

addhelp(flparam,"flparam(): parameters of floating-point arithmetic"\
" in current precision [base, digits, machine epsilon]")



/* References

1. How to know the internal basis of your computer (code for Pari 2.1.4):

   { x=y=1.0; while(((x+1.0)-x)==1.0, x=2.0*x ); while((x+y)-x<>y, y=y+1.0); [x,y] }

   in MPFR: A multiple-precision floating-point libraby with correct rounding,
   by Paul Zimmermann, Workshop: The PARI/GP System, IHP, 2004,
   <http://pari.math.u-bordeaux.fr/Events/IHP2004/Paul.Zimmermann/mpfr2.ps.gz>

2. User's Guide to the PARI library by the PARI Group, 2011, 4.5.2: Type t_REAL.

3. User's Guide to PARI/GP by the PARI Group, 2011, 2.3.2: Real numbers (t_REAL).

4. Algorithms to reveal properties of floating-point arithmetic
   by Michael A. Malcolm, CACM 15 (1972), pp. 949-951.

5. Computer Methods for Mathematical Computations by George E. Forsythe,
   Michael A. Malcolm, and Cleve B. Moler, Prentice-Hall, 1977, pp. 10-14.

6. What Every Computer Scientist Should Know About Floating-Point Arithmetic,
   by David Goldberg, published in the March, 1991 issue of Computing Surveys,
   reprinted with permission as Appendix D of Numerical Computation Guide:
   <http://download.oracle.com/docs/cd/E19957-01/806-3568/ncgTOC.html>

*/