[Openmcl-devel] representing infinity

Gary Byers gb at clozure.com
Fri Mar 19 17:28:01 PST 2004



On Fri, 19 Mar 2004, Gary King wrote:

> Is there a way in OpenMCL to represent IEEE positive and negative
> infinity? An apropos on NAN gives me (among other things):
>
>   CCL::IEEE-DOUBLE-FLOAT-SIGNALLING-NAN-BIT,  Value: 51
>   CCL::IEEE-SINGLE-FLOAT-SIGNALLING-NAN-BIT,  Value: 22
>   CCL::NAN-OR-INFINITY-P, Def: FUNCTION
>   CCL::NANNING
>   CCL::PRINT-A-NAN, Def: FUNCTION
>
> and one on "INFINITY" gives:
>
> CCL::INFINITY-P, Def: FUNCTION
>
> This is promising but even after looking at the source code it's not
> clear to me how to produce something such that (infinity-p <something>)
> returns t.
>
> Thanks,
> --
> Gary Warren King, Lab Manager
> EKSL East, University of Massachusetts * 413 577 0176
>

It's easy to "represent" an infinity or a NaN, since the hardwre does
all of the hard work ...

It's a little harder to produce one: FP operations whose results can't
be represented (either because they're mathematically undefined or
because their magnitude is too great) will generally either:

a) raise an exception if that exception is enabled in the FPU in the
current thread
b) produce a NaN or an infinity otherwise.

When a lisp thread starts up, IEEE OVERFLOW, DIVISION-BY-ZERO, and
INVALID-OPERATION exceptions are enabled:

? (ccl:get-fpu-mode)
(:ROUNDING-MODE :NEAREST :OVERFLOW T :UNDERFLOW NIL :DIVISION-BY-ZERO T :INVALID T :INEXACT NIL)

so trying to do something that'd cause an overflow will generate a hardware
exception (which is mapped to a lisp condition):

? (* 2 most-positive-single-float)
> Error in process listener(1): FLOATING-POINT-OVERFLOW detected
>                               performing * on (3.4028235E+38 1.0842021E-19)
> While executing: %SHORT-FLOAT*-2!
> Type :POP to abort.
Type :? for other options.
1 >

[There's a bug there, in that the second operand is some more-or-less random
number instead of 2.0.]

If we disable the overflow exception, the result will be an infinity:
? (ccl:set-fpu-mode :overflow nil)

then:

? (* 2 most-positive-single-float)
#<INFINITY >



More information about the Openmcl-devel mailing list