Changeset 12940


Ignore:
Timestamp:
10/02/10 21:39:52 (11 years ago)
Author:
ehuelsmann
Message:

Fix loss of precision in (expt <non-double> <complex-double>),
fixes last Maxima failure.

Location:
trunk/abcl/src/org/armedbear/lisp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/Complex.java

    r12431 r12940  
    7979  {
    8080    return imagpart;
     81  }
     82
     83  /** Coerces the complex parts into DoubleFloats
     84   *
     85   * @return a new complex with double-float real and imaginary parts
     86   */
     87  public LispObject coerceToDoubleFloat() {
     88      return getInstance(DoubleFloat.coerceToFloat(realpart),
     89                         DoubleFloat.coerceToFloat(imagpart));
    8190  }
    8291
  • trunk/abcl/src/org/armedbear/lisp/MathFunctions.java

    r12922 r12940  
    624624            // for anything not a rational or complex rational, use
    625625            // float approximation.
     626            boolean wantDoubleFloat = false;
     627            if (base instanceof DoubleFloat)
     628                wantDoubleFloat = true;
     629            else if (power instanceof DoubleFloat)
     630                wantDoubleFloat = true;
     631            else if (base instanceof Complex
     632                     && (((Complex)base).getRealPart() instanceof DoubleFloat
     633                         || ((Complex)base).getImaginaryPart() instanceof DoubleFloat))
     634                wantDoubleFloat = true;
     635            else if (power instanceof Complex
     636                    && (((Complex)power).getRealPart() instanceof DoubleFloat
     637                         || ((Complex)power).getImaginaryPart() instanceof DoubleFloat))
     638                wantDoubleFloat = true;
     639
     640            if (wantDoubleFloat) {
     641                if (power instanceof Complex)
     642                    power = ((Complex)power).coerceToDoubleFloat();
     643                else
     644                    power = DoubleFloat.coerceToFloat(power);
     645
     646                if (base instanceof Complex)
     647                    base = ((Complex)base).coerceToDoubleFloat();
     648                else
     649                    base = DoubleFloat.coerceToFloat(base);
     650            }
     651
     652
     653
    626654            if (base instanceof Complex || power instanceof Complex)
    627655                return exp(power.multiplyBy(log(base)));
Note: See TracChangeset for help on using the changeset viewer.