More subtlety with arbitrary run-time precision (caveat programmator): $ clisp [...

@vnikolov@ieji.de

More subtlety with arbitrary run-time precision (caveat programmator):

$ clisp
[1]> (defun e () "Return the value of e as a `long-float'." (exp 1L0))
E
[2]> (setf (long-float-digits) (* 16 (long-float-digits)))
1024
[3]> (expt (e) (* pi #C(0L0 1L0)))
#C(-1.0L0 -7.845150826357264567L-20) ;Mathematically, a real number, of course.

;; Hmmm, too inaccurate.

[4]> (integer-decode-float (imagpart *))
13347832460223031479 ;
-127 ;
-1

;; Too inaccurate indeed.

;; Do you notice what Puck did?

[5]> (e)
2.7182818284590452354L0

[6]> (describe #'e)

#<FUNCTION E NIL "Return the value of e as a `long-float'." (DECLARE (SYSTEM::IN-DEFUN E)) (BLOCK E (EXP 1.0L0))> is an interpreted function.
Argument list: ()
Documentation: Return the value of e as a `long-float'.

;; Not compiled, by the way, not that it matters here.

;;; Take two:

$ clisp
[1]> (setf (long-float-digits) (* 16 (long-float-digits)))
1024
[2]> (defun e () "Return the value of e as a `long-float'." (exp 1L0))
E

;; Yes, it's different now:

[3]> (e)
2.71828182845904523536028747135266249775724709369995957496696762772407663035354759457138217852516642742746639193200305992181741359662904357290033429526059563073813232862794349076323382988075319525101901157383418793070215408914993488416750924476146066808226480016847741185374234544243710753907774499206955170277L0
[4]> (expt (e) (* pi #C(0L0 1L0)))
#C(-1.0L0
4.4159741848488758531726160656089533202761352843950741810509537213649392995282943592745789204277939266569808322194586729569872670819480502770846786874305201718215791310948505090575804581063383254057295785111584108995354602565727992662846155123312661407353868677580854724681334059286394407931654623717140025991L-309)
[5]> (integer-decode-float (imagpart *))
142711064542513797375761164792883845232670401481971869708584082397661513134960289997663095233931200321823663175395230178627245138199368488725376466632604576788052034909463540163675838543561814928154094082496959718469512486587999806404204178019545267375820679176559019490895257943507931319481850929509967670757 ;
-2048 ;
1

;; Hunky-dory: accurate to its precision.

*Exercise for the reader:*
how to fix the above naive definition of `e'?

#ArbitraryPrecision
#ChangingPrecision
#CommonLisp
#Lisp
#NumericComputation