Lisp HUG Maillist Archive

Suppressing the arithmetic-error condition

Hello All!

Is there a way to suppress signaling the arithmetic-error conditions 
such as division-by-zero or floating-point-overflow during the extensive 
numeric calculations?

I know that it is possible to handle the conditions with help of the 
handler-case form but it is too slow in my particular scenario as I have 
to divide the computation into many pieces.

It doesn't conform to the ANSI standard but I would like the following 
code return either 1d+-0 (nan) or -1d++0 (-infinity):

cl-user > (log (/ 1 1d++0))
Error: Arithmetic error in LOG of (0.0D0): Argument must not be zero.

For example, Scala returns -Infinity in this case:

scala> math.log(1 / Double.PositiveInfinity)
res1: Double = -Infinity

It seems there are flags in some CL implementations to control this 
behaviour, although I'm not quite sure. Is there something similar for 
LispWorks?

Thanks,
David

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Re: Suppressing the arithmetic-error condition

In the course of discussing it with Ala'a Mohammad, I arrived at a 
conclusion that the current behavior of LW is rather good. In other 
cases I indeed get either NaN or infinity as I need. Probably, the 
number of cases, when the division-by-zero condition is raised, is not 
so great. At least, it is better to have a signal than an incorrect 
result as in case of Scala:

scala> math.log (1 / Double.NegativeInfinity)
res0: Double = -Infinity

while the limit (= lim_{x -> -0}{log(x)}) doesn't even exist (but 
constants -0 and +0 would help to find a correct answer).

I think this is a difficult subject.

Thanks,
David

16.01.2013 10:27, David Sorokin пишет:
>
> Hello All!
>
> Is there a way to suppress signaling the arithmetic-error conditions 
> such as division-by-zero or floating-point-overflow during the 
> extensive numeric calculations?
>
> I know that it is possible to handle the conditions with help of the 
> handler-case form but it is too slow in my particular scenario as I 
> have to divide the computation into many pieces.
>
> It doesn't conform to the ANSI standard but I would like the following 
> code return either 1d+-0 (nan) or -1d++0 (-infinity):
>
> cl-user > (log (/ 1 1d++0))
> Error: Arithmetic error in LOG of (0.0D0): Argument must not be zero.
>
> For example, Scala returns -Infinity in this case:
>
> scala> math.log(1 / Double.PositiveInfinity)
> res1: Double = -Infinity
>
> It seems there are flags in some CL implementations to control this 
> behaviour, although I'm not quite sure. Is there something similar for 
> LispWorks?
>
> Thanks,
> David
>
> _______________________________________________
> Lisp Hug - the mailing list for LispWorks users
> lisp-hug@lispworks.com
> http://www.lispworks.com/support/lisp-hug.html
>
>
>


_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Updated at: 2020-12-10 08:36 UTC