[Gbbopen-developer] Floating point Infinities and NaN's?
Gary King
gwking at metabang.com
Sun Aug 5 15:54:19 EDT 2007
David,
I've only been following your discussion from afar but you might want
to look at the GBBopen source as I'm pretty sure that there are
portable versions of at least some of what you're looking for. (see
http://www.gbbopen.org/)
regards,
On Aug 5, 2007, at 1:55 PM, David McClain wrote:
> Hi all,
>
> I wonder if any of you know the preferred manner of testing for
> floating point infinities or NaN's in Common Lisp?
>
> So far, what I've come up with is to enshroud the computation with
> a HANDLER-CASE, to trap the invalid operations, and then for those
> operations which "succeed" to test for an infinity by looking to
> see whether its reciprocal is zero...
>
> (in my case, I'm also looking to be sure the result is a real-
> value, not a complex value)
> -----------------------------------
> ;; test for infinities
> (defun infinitep (v)
> (and (not (zerop v))
> (zerop (/ v))))
>
> ;; careful evaluation with tests for infinities and non-real results
> (defun real-eval-with-nans (fn &rest args)
> (handler-case
> (let ((v (apply fn args)))
> (if (or (complexp v)
> (infinitep v))
> :nan
> v))
> (error (err)
> (declare (ignore err))
> :nan)))
>
> ;; catchall predicate for both NaN's and infinities
> (defun nanp (v)
> (or (eq v :nan)
> (infinitep v)))
>
> -------------------------------------
> I find it interesting that Common Lisp will generate infinite
> results, and consider them as numbers, but does not appear to offer
> any method for testing for such results, or for classifying numbers
> as per the IEEE FP Standard.
>
> I do see that NaN's are never actually generated since the
> operations that would produce them are trapped as invalid, or else
> produce complex results. So the NaN's are my own invention here, I
> guess. But infinities are not.
>
> David McClain
> Chief Technical Officer
> Refined Audiometrics Laboratory
> 4391 N. Camino Ferreo
> Tucson, AZ 85750
>
> email: dbm at refined-audiometrics.com
> phone: 1.520.390.3995
> web: http://www.refined-audiometrics.com
> Skype: dbmcclain
>
>
--
Gary Warren King, metabang.com
Cell: (413) 885 9127
Fax: (206) 338-4052
gwkkwg on Skype * garethsan on AIM
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://GBBopen.org/pipermail/gbbopen-developer/attachments/20070805/56f9e33f/attachment.html
More information about the Gbbopen-developer
mailing list