[Openmcl-devel] Infinity and NaN

Ron Garret ron at flownet.com
Mon Jul 19 12:13:28 PDT 2010


On Jul 19, 2010, at 12:02 PM, R. Matthew Emerson wrote:

> 
> On Jul 19, 2010, at 12:35 PM, Liam Healy wrote:
> 
>> I'm having trouble defining variables that create infinities and NaNs.
>> I am using GSL
>> http://www.gnu.org/software/gsl/manual/html_node/Infinities-and-Not_002da_002dnumber.html
>> to do this; here for example is my definition
>> 
>> (defconstant +nan+
>> (ignore-errors
>>   (cffi:foreign-funcall "gsl_nan" :double)))
>> 
>> If I put this form into the listener, it loads fine, and
>> 
>> +nan+
>> 1D+-0 #| not-a-number |#
>> 
>> However, if I put this definition into a file to compile it,
>> 
>> ASDF could not load gsll because FLOATING-POINT-INVALID-OPERATION detected
>> performing LOG on (1.0).
>>> Error: FLOATING-POINT-INVALID-OPERATION detected
>>>      performing LOG on (1.0)
>>> While executing: CCL::%FP-ERROR-FROM-STATUS, in process listener(1).
>>> Type :POP to abort, :R for a list of available restarts.
>>> Type :? for other options.
>> 
>> I'm not sure where this is coming from, nor why taking the log
>> of 1.0 should be a problem.
> 
> I recently changed how ccl deals with floating-point exceptions in foreign code (on x86-64), so I may have introduced or exposed a bug here.
> 
> At the risk of boring everyone, I will explain the change.
> 
> We used to unconditionally mask (disable) all floating point exceptions when calling a foreign function.  It's not free to save/restore the MXCSR (the register that contains fp status and control bits) around every foreign function call, so we now leave fp exceptions enabled (as configured by ccl:set-fpu-mode).  The runtime will notice when an fp exception takes place in foreign code, mask all fp exceptions, and try the call again.

Huh?  Does that mean that if I call the following foreign function once:

void foo() {
  call_once();
  sqrt(-1.0);
}

that call_once will be called twice?

rg




More information about the Openmcl-devel mailing list