bigfloats?

Aidan Kehoe kehoea at parhasard.net
Wed Feb 4 10:37:12 EST 2009


 Ar an ceathrú lá de mí Feabhra, scríobh Giacomo Boffi: 

 > Aidan Kehoe writes:
 >  > 
 >  >  Ar an ceathrú lá de mí Feabhra, scríobh Giacomo Boffi: 
 >  > 
 >  >  > my question: how can i use bigfloats in my computations? i have to say
 >  >  > that the xemacs user manual was slightly unhelpful...
 >  > 
 >  > It seems buggy to me,
 > 
 > smells of bit-rot... does "make check" test bignums?

Yes, but it doesn’t test the bigfloat functions. 

 >  > and it certainly doesn’t have the nice
 >  > convert-to-bignum-on-overflow behaviour that integer computations have. 
 >  > For your particular example there, you can do:
 >  > 
 >  >   (insert (format "%g" (expt (coerce e 'bigfloat) 710)))
 >  > 
 >  > That gives me 8221840746155466228226, instead of the 308-digit number I
 >  > expected.
 > 
 > for me, it is 2223399476616162667098 

Whoops, yes, me too; (expt (coerce e 'bigfloat) 709) gives the number
starting with 8 that should print as 308 digits long. 

If I replace the implementation of bigfloat_to_string in number-gmp.c with
that of bigf_to_string from SXEmacs, then I get the 308-digit number; it
doesn’t have a trailing .0, though, for some reason. It is then read as a
bignum. SXEmacs has the same behaviour. I don’t know what Common Lisp
specifies.

 >  > If I set default-float-precision to some higher value, I get
 >  > constantly-increasing numbers printed. 
 > 
 > this also is nice:
 > 
 > (coerce 710 'bigfloat) 
 > 71 
 > (coerce 711 'bigfloat) 
 > 711. 

Ouch. 

 > also
 > (expt (coerce e 'bigfloat) (coerce 711 'bigfloat)) 
 > gives me an arithmetic range error... and finally

SXEmacs tells me “Operation undefined over domain”. 

 > (let ((a (coerce 1E100 'bigfloat))) 
 >   (print (* a a)) 
 >   (print (+ a a)) 
 >   (print (* 10 a)) 
 >   (print (+ a a a a a a a a a a)) ; (* 10 a) 
 >   nil 
 >   ) 
 > 1000000000000000003181 
 > 2000000000000000003181 
 > 100000000000000000159 
 > 100000000000000000159 
 > nil 

They give better behaviour with the replaced implementation of
bigfloat_to_string. 

 > ok, for now i'll forget my experiments with bigfloats
 > 
 > thank you Aidan

You’re welcome; sorry I don’t have better news.

-- 
¿Dónde estará ahora mi sobrino Yoghurtu Nghe, que tuvo que huir
precipitadamente de la aldea por culpa de la escasez de rinocerontes?




More information about the XEmacs-Beta mailing list