Out of range floating point number determination



On 8/12/12 4:43 PM, Richard Fateman wrote:
> On 8/12/2012 4:11 PM, Robert Dodier wrote:
>> On 2012-08-11, Edward A Romana <erom at earthlink.net> wrote:
>>
>>>  From the Maxima level, I would like to determine when evaluation of a
>>> floating point expression is out of range.
>> The Common Lisp standard does not allow for non-numerical float values
>> such as infinity, negative infinity, and not-a-number.
> Eh, I think it allows them but does not require them.
>>   So any having to
>> do with such floats is implementation-dependent.
> This is not actually necessary to help Edward.
> There is a standard suite of stuff for handling errors in Lisp:
> 
> (defun ten2p (p) (handler-case (expt 10.0 p) (arithmetic-error (v) 'und)))
> 
> computes 10.0^p.   When this causes an error, it returns the symbol 'und.
> 
> You can read all about it in the common lisp documentation online.
> From the Maxima top level this would not, I think, be something you can
> utter.
> 
> However a little bit of lisp should work if you can avoid evaluation and
> then do it later.
> There is an mfexpr* property or something like that which can be used. 
> I haven't debugged it but
> maybe
> (defprop $catcharith (lambda(x)(handler-case (meval x)
> (arithmetic-error(v) '$und))) mfexpr*)
> 
> then at maxima top level
> 
> (%i10)    catcharith(10.0^319);
> might return und.

The parser could probably be massaged to catch floats that are too big.

It would be nice if we could get gcl to signal errors for IEEE errors
like overflow, divide-by-zero, and invalid-operation.  I think most
other lisps have some option to do this.  (I personally don't like float
operations returning NaN since they propagate forever and I never find
NaN being useful at the end of some long computation.)

Perhaps Camm can give us the magic gcl options to enable these?

Ray