Page 1 of 1

Is there a way to represent infinity in Common Lisp in an im

Posted: Mon Oct 14, 2013 8:19 am
by joeish80829
Is there an implementation independent way of representing infinity or not a number (NAN) in Common Lisp? It would need to be a double float, and have both positive and negative values. In SBCL, the results of

(apropos "INFINITY")

include

SB-EXT:DOUBLE-FLOAT-NEGATIVE-INFINITY (bound)
SB-EXT:DOUBLE-FLOAT-POSITIVE-INFINITY (bound)

but I need it to be available in all implementations. I have an addendum to a package to write that runs on all platforms and it needs a representation of infinity and NAN. Even functions from another library would suffice.

Re: Is there a way to represent infinity in Common Lisp in a

Posted: Mon Oct 14, 2013 9:03 am
by edgar-rft
According to CLHS 12.1.4.3 Rule of Float Underflow and Overflow floating-point infinity is an arithmetic error:
CLHS 12.1.4.3 wrote:An error of type floating-point-overflow or floating-point-underflow should be signaled if a floating-point computation causes exponent overflow or underflow, respectively.
Where "floating-point underflow" means a numer so close to zero that it cannot be represented by the smallest floating-point number of the respective floating-point format anymore.

I have no idea how to get a portable solution, but a very similar discussion can be found here:
- edgar

Re: Is there a way to represent infinity in Common Lisp in a

Posted: Mon Oct 14, 2013 9:53 am
by joeish80829
can you help me represent not a number (NAN) i would really appreeciate any help on this

Re: Is there a way to represent infinity in Common Lisp in a

Posted: Mon Oct 14, 2013 10:10 am
by edgar-rft
Just an idea, don't know how much this really helps:
The IEEE-Floats library can decode floats given in IEEE binary format and map non-numbers like Inf and NaN to Common Lisp keywords like :not-a-number, :positive-infinity, and :negative-infinity. This could help to identify non-numbers computed by the C-code.

Caution: The big disadvantage is that not a single built-in Common Lisp math function will work with the :not-a-number, :positive-infinity, and :negative-infinity keywords, so either the keywords must be filtered out directly after the conversion or you must write your own math functions that can compute with the :not-a-number, :positive-infinity, and :negative-infinity keywords.

- edgar

Re: Is there a way to represent infinity in Common Lisp in a

Posted: Mon Oct 14, 2013 8:00 pm
by joeish80829
ok i got iee-floats loaded and its part of my library now. I have a function that detects if a number is nan and one that detects whether a number is infinity havent tested nan out but my infinity function needs the number to be a double-float ....SBCL's SB-EXT:DOUBLE-FLOAT-POSITIVE-INFINITY works but i would need it to be implimentation independent ....ny advice from here