Tutorial :Package RCL and Inf



Question:

this will be a difficult question to answer, I contacted the author but still no replies I'll give it a shot here: In the package RCL (http://common-lisp.net/project/rcl/) examples:

(in-package :rcl)  (r-init)    (r "/" 1 5)  RCL> 0.2d0    (r "print" (r% "/" 1 5))  RCL> ;R# [1] 0.2  0.2d0  

The above is ok, but

(r "/" 1 0)  RCL>> #<a FLOATING-POINT-OVERFLOW>   

broken

(r "print" (r% "/" 1 0))  RCL>> ;R# [1] Inf  #<a FLOATING-POINT-OVERFLOW>   

broken

or (r "log" 0)

How to get around this so that when R gets to an inf value my Lisp doesn't break but just gives a message that an inf value is computed; The above is a simple example but there are times when we have during a statistical procedure divisions by zero that nevertheless do not invalidate the results and R returns a final value (like during optimization), but this unfortunately crashes while using RCL.


Solution:1

Ok I got the answer from the author I post here: support for IEEE floating-point infinities is platform-dependent. The following Lisps work, at least on this system (MacOSX):

SBCL

R> (r "/" 1 0)  .SB-EXT:DOUBLE-FLOAT-POSITIVE-INFINITY  R> (r "log" 0)  .SB-EXT:DOUBLE-FLOAT-NEGATIVE-INFINITY  

Allegro CL

R> (r "/" 1 0)  .EXCL:*INFINITY-DOUBLE*  R> (r "log" 0)  .EXCL:*NEGATIVE-INFINITY-DOUBLE*  

LispWorks

R> (r "/" 1 0)  +1D++0 #| +1D++0 is double-float plus-infinity  R> (r "log" 0)  -1D++0 #| -1D++0 is double-float minus-infinity  

CMUCL doesn't (X86:SIGFPE-HANDLER, no exceptions enabled), but I think this can be fixed (http://common-lisp.net/project/cmucl/doc/cmu-user/extensions.html#float-traps).

ECL is the last one that I tried, and it's apparently the one you use (I got the same FLOATING-POINT-OVERFLOW exception). It seems that it also allows to disable overflow checks using SI:TRAP-FPE, this might be what you need (the following example is taken from http://www.lispforum.com/viewtopic.php?f=2&t=386):

(let* ((bits (si::trap-fpe 'last nil)))     (prog1 (/ 1.0 0.0)       (si::trap-fpe bits t)))  .SI:SINGLE-FLOAT-POSITIVE-INFINITY  

Also this works in general:

(handler-case (r "/" 2 0)    (floating-point-overflow () nil))  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »