bug-guile
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem diving complex numbers


From: Kevin Ryde
Subject: Re: Problem diving complex numbers
Date: Sat, 30 Apr 2005 08:49:21 +1000
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3 (gnu/linux)

Jean Crepeau <address@hidden> writes:
>
> There appears to be a bug in the 1.6.x releases of guile which wasn't 
> there in the 1.4.1 (and probably other versions before).

Yep, but those versions are prone to overflow when re or im is above
sqrt(DBL_MAX).

> Simply doing
>
>    (/ 0-1i)
>
> will result in #.##.#i

Thanks.  Looks like nobody ever divided by -i before :).  I think it's
meant to be like:

--- numbers.c.~1.135.2.20.~     2005-02-21 09:50:34.000000000 +1100
+++ numbers.c   2005-04-29 14:19:10.535828592 +1000
@@ -3738,7 +3738,7 @@
     } else if (SCM_COMPLEXP (x)) {
       double r = SCM_COMPLEX_REAL (x);
       double i = SCM_COMPLEX_IMAG (x);
-      if (r <= i) {
+      if (fabs(r) <= fabs(i)) {
        double t = r / i;
        double d = i * (1.0 + t * t);
        return scm_make_complex (t / d, -1.0 / d);
@@ -3782,7 +3782,7 @@
       {
        double r = SCM_COMPLEX_REAL (y);
        double i = SCM_COMPLEX_IMAG (y);
-       if (r <= i) {
+        if (fabs(r) <= fabs(i)) {
          double t = r / i;
          double d = i * (1.0 + t * t);
          return scm_make_complex ((a * t) / d,  -a / d);
@@ -3873,7 +3873,7 @@
     } else if (SCM_COMPLEXP (y)) {
       double ry = SCM_COMPLEX_REAL (y);
       double iy = SCM_COMPLEX_IMAG (y);
-      if (ry <= iy) {
+      if (fabs(ry) <= fabs(iy)) {
        double t = ry / iy;
        double d = iy * (1.0 + t * t);
        return scm_make_complex ((rx * t + ix) / d, (ix * t - rx) / d);

reply via email to

[Prev in Thread] Current Thread [Next in Thread]