Subject: Out of range floating point number determination
From: Richard Fateman
Date: Sun, 12 Aug 2012 16:43:13 -0700
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.
except I haven't tried this, and I am unsure about the mfexpr*
RJF
> Some implementations
> allow such values, some don't. Clisp doesn't, SBCL does; I don't
> remember about any others.
>
> I wonder what is your larger goal here. If you are trying to avoid
> float(x) where x is too big so it causes an error, my advice is to
> switch to an implementation, such as SBCL, which allows non-numerical
> floats.
Producing an NaN and passing it around within Maxma is not necessarily
going to work.
> That might obviate the need for such logic in your own code.
>
>> I had no luck finding i.nf*10^0 in the documentation.
> It is probably a messed-up version of an implementation-dependent name
> for float infinity. I suppose that's a bug in EXPLODEN (function to
> format numbers for display).
yep.
>
> Hope this helps,
>
> Robert Dodier
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima