Changeset 3561


Ignore:
Timestamp:
09/02/03 18:51:45 (19 years ago)
Author:
piso
Message:

multiplyBy(), divideBy(): support complex numbers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/lisp/Fixnum.java

    r3558 r3561  
    33 *
    44 * Copyright (C) 2002-2003 Peter Graves
    5  * $Id: Fixnum.java,v 1.58 2003-09-02 18:26:05 piso Exp $
     5 * $Id: Fixnum.java,v 1.59 2003-09-02 18:51:45 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    271271        if (obj instanceof LispFloat)
    272272            return new LispFloat(value * LispFloat.getValue(obj));
     273        if (obj instanceof Complex) {
     274            Complex c = (Complex) obj;
     275            return Complex.getInstance(multiplyBy(c.getRealPart()),
     276                                       multiplyBy(c.getImaginaryPart()));
     277        }
    273278        throw new TypeError(obj, "number");
    274279    }
     
    281286                return new Fixnum(value / divisor);
    282287            return number(BigInteger.valueOf(value),
    283                 BigInteger.valueOf(divisor));
     288                          BigInteger.valueOf(divisor));
    284289        }
    285290        if (obj instanceof Bignum)
     
    293298        if (obj instanceof LispFloat)
    294299            return new LispFloat(value / LispFloat.getValue(obj));
     300        if (obj instanceof Complex) {
     301            Complex c = (Complex) obj;
     302            LispObject realPart = c.getRealPart();
     303            LispObject imagPart = c.getImaginaryPart();
     304            LispObject denominator =
     305                realPart.multiplyBy(realPart).add(imagPart.multiplyBy(imagPart));
     306            return Complex.getInstance(multiplyBy(realPart).divideBy(denominator),
     307                                       Fixnum.ZERO.subtract(multiplyBy(imagPart).divideBy(denominator)));
     308        }
    295309        throw new TypeError(obj, "number");
    296310    }
Note: See TracChangeset for help on using the changeset viewer.