Changeset 3574


Ignore:
Timestamp:
09/04/03 05:06:39 (19 years ago)
Author:
piso
Message:

divideBy()

File:
1 edited

Legend:

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

    r3570 r3574  
    33 *
    44 * Copyright (C) 2003 Peter Graves
    5  * $Id: Complex.java,v 1.15 2003-09-04 04:28:01 piso Exp $
     5 * $Id: Complex.java,v 1.16 2003-09-04 05:06:39 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    144144    }
    145145
     146    public LispObject divideBy(LispObject obj) throws LispError
     147    {
     148        if (obj instanceof Complex) {
     149            LispObject a = realpart;
     150            LispObject b = imagpart;
     151            LispObject c = ((Complex)obj).getRealPart();
     152            LispObject d = ((Complex)obj).getImaginaryPart();
     153            LispObject ac = a.multiplyBy(c);
     154            LispObject bd = b.multiplyBy(d);
     155            LispObject bc = b.multiplyBy(c);
     156            LispObject ad = a.multiplyBy(d);
     157            LispObject denominator = c.multiplyBy(c).add(d.multiplyBy(d));
     158            return Complex.getInstance(ac.add(bd).divideBy(denominator),
     159                                       bc.subtract(ad).divideBy(denominator));
     160        }
     161        return Complex.getInstance(realpart.divideBy(obj),
     162                                   imagpart.divideBy(obj));
     163    }
     164
    146165    public boolean isEqualTo(LispObject obj) throws LispError
    147166    {
Note: See TracChangeset for help on using the changeset viewer.