Lisp HUG Maillist Archive

1D+-0 is double-float not-a-number

Hi,

I have some floating point code that occasionally goes astray  
(divides numbers that are too big). For example,

 > (/ 1.0E1000 1.0E1000)
1D+-0 #| 1D+-0 is double-float not-a-number |#

I'm wondering if there's a way to check for this value in the  
algorithm and abort or do something useful if the calculations go out  
of bounds.  It seems like there should be some sort of built-in  
function for this, but I can't find it. So far I've tried:

  > (numberp (/ 1.0E1000 1.0E1000))
T

  > (floatp (/ 1.0E1000 1.0E1000))
T

 > (= (/ 1.0E1000 1.0E1000) 1D+-0)
NIL

Thanks,
-Chris



Nevermind: 1D+-0 is double-float not-a-number

Never mind -- I searched the archive for this list and found a solution:

(defun nanp (v)
  (and (numberp v)
       (not (or (minusp v)
                (zerop  v)
                (plusp  v)))
       ))

On Aug 25, 2008, at 3:46 PM, Chris Sims wrote:

Hi,

I have some floating point code that occasionally goes astray (divides numbers that are too big). For example,

> (/ 1.0E1000 1.0E1000)
1D+-0 #| 1D+-0 is double-float not-a-number |#

I'm wondering if there's a way to check for this value in the algorithm and abort or do something useful if the calculations go out of bounds.  It seems like there should be some sort of built-in function for this, but I can't find it. So far I've tried:

 > (numberp (/ 1.0E1000 1.0E1000))
T

 > (floatp (/ 1.0E1000 1.0E1000))
T

> (= (/ 1.0E1000 1.0E1000) 1D+-0)
NIL

Thanks,
-Chris


Updated at: 2020-12-10 08:42 UTC