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

Discussion of Common Lisp

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

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.
Last edited by joeish80829 on Mon Oct 14, 2013 9:51 am, edited 1 time in total.
joeish80829

Posts: 153
Joined: Tue Sep 03, 2013 5:32 am

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

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
edgar-rft

Posts: 224
Joined: Fri Aug 06, 2010 6:34 am
Location: Germany

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

can you help me represent not a number (NAN) i would really appreeciate any help on this
joeish80829

Posts: 153
Joined: Tue Sep 03, 2013 5:32 am

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

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
edgar-rft

Posts: 224
Joined: Fri Aug 06, 2010 6:34 am
Location: Germany

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

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
joeish80829

Posts: 153
Joined: Tue Sep 03, 2013 5:32 am