[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Divide by zero or how to overload a function
From: |
Chris Cramer |
Subject: |
Re: Divide by zero or how to overload a function |
Date: |
Tue, 23 Oct 2001 01:17:20 -0500 |
User-agent: |
Mutt/1.2.5i |
On Tue, Oct 23, 2001 at 01:29:46AM -0400, Keith Wright wrote:
> Now here's a question for the wizards.
> Why does (/ 0) have a different result from (/ 1 0)?
>
> guile> (/ 1 0)
> standard input:203:1: In procedure / in expression (/ 1 0):
> standard input:203:1: Numerical overflow
> ABORT: (numerical-overflow)
> guile> (/ 0)
> +#.#
Here are the relevant parts of numbers.c:
if (SCM_UNBNDP (y)) {
if (SCM_UNBNDP (x)) {
SCM_WTA_DISPATCH_0 (g_divide, s_divide);
} else if (SCM_INUMP (x)) {
if (SCM_EQ_P (x, SCM_MAKINUM (1L)) || SCM_EQ_P (x, SCM_MAKINUM (-1L))) {
return x;
} else {
return scm_make_real (1.0 / (double) SCM_INUM (x));
[...much deleted...]
if (SCM_INUMP (x)) {
long xx = SCM_INUM (x);
if (SCM_INUMP (y)) {
long yy = SCM_INUM (y);
if (yy == 0) {
scm_num_overflow (s_divide);
Notice that (/ 1.0 0.0) gives the same result as (/ 0):
guile> (/ 1.0 0.0)
+#.#
It looks like a bug. Whatever the result (/ 1.0 0.0) should be, (/ 0)
and (/ 1 0) should give the same result. I guess just add a check for
zero right before the "return scm_make_real..." line?
--
C. Ray C. aka Christopher Cramer
address@hidden
http://www.pyro.net/~crayc/
Re: Divide by zero or how to overload a function, Robert A. Uhl, 2001/10/22