Changeset 9960


Ignore:
Timestamp:
09/12/05 10:51:40 (16 years ago)
Author:
piso
Message:

sqrt(): (sqrt (complex n 0.0)) => (complex (sqrt n) 0.0)

File:
1 edited

Legend:

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

    r9959 r9960  
    33 *
    44 * Copyright (C) 2004-2005 Peter Graves
    5  * $Id: MathFunctions.java,v 1.30 2005-09-12 01:53:18 piso Exp $
     5 * $Id: MathFunctions.java,v 1.31 2005-09-12 10:51:40 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    611611            return new SingleFloat((float)Math.sqrt(SingleFloat.coerceToFloat(obj).value));
    612612        }
    613         if (obj instanceof Complex)
     613        if (obj instanceof Complex) {
     614            LispObject imagpart = ((Complex)obj).imagpart;
     615            if (imagpart.zerop())
     616                return Complex.getInstance(sqrt(((Complex)obj).realpart),
     617                                           imagpart);
    614618            return exp(log(obj).divideBy(Fixnum.TWO));
     619        }
    615620        return signalTypeError(obj, Symbol.NUMBER);
    616621    }
Note: See TracChangeset for help on using the changeset viewer.