Changeset 3559


Ignore:
Timestamp:
09/02/03 18:29:02 (20 years ago)
Author:
piso
Message:

SQRT

File:
1 edited

Legend:

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

    r3556 r3559  
    33 *
    44 * Copyright (C) 2002-2003 Peter Graves
    5  * $Id: Primitives.java,v 1.365 2003-09-02 17:40:29 piso Exp $
     5 * $Id: Primitives.java,v 1.366 2003-09-02 18:29:02 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    47884788    };
    47894789
     4790    // ### sqrt
     4791    private static final Primitive1 SQRT =
     4792        new Primitive1("sqrt") {
     4793        public LispObject execute(LispObject arg) throws LispError
     4794        {
     4795            if (arg instanceof Complex)
     4796                throw new LispError("SQRT not implemented for complex numbers");
     4797            if (arg.minusp())
     4798                return Complex.getInstance(new LispFloat(0),
     4799                                           sqrt(Fixnum.ZERO.subtract(arg)));
     4800            return sqrt(arg);
     4801        }
     4802    };
     4803
     4804    private static final LispFloat sqrt(LispObject obj) throws TypeError
     4805    {
     4806        if (obj instanceof Fixnum)
     4807            return new LispFloat((float)Math.sqrt(((Fixnum)obj).getValue()));
     4808        if (obj instanceof Bignum)
     4809            return new LispFloat((float)Math.sqrt(((Bignum)obj).floatValue()));
     4810        if (obj instanceof Ratio)
     4811            return new LispFloat((float)Math.sqrt(((Ratio)obj).floatValue()));
     4812        if (obj instanceof LispFloat)
     4813            return new LispFloat((float)Math.sqrt(((LispFloat)obj).getValue()));
     4814        throw new TypeError(obj, "number");
     4815    }
     4816
    47904817    // ### hashcode-to-string
    47914818    private static final Primitive1 HASHCODE_TO_STRING =
Note: See TracChangeset for help on using the changeset viewer.