Changeset 3569


Ignore:
Timestamp:
09/04/03 03:52:38 (19 years ago)
Author:
piso
Message:

LOG

File:
1 edited

Legend:

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

    r3567 r3569  
    33 *
    44 * Copyright (C) 2002-2003 Peter Graves
    5  * $Id: Primitives.java,v 1.368 2003-09-04 00:16:39 piso Exp $
     5 * $Id: Primitives.java,v 1.369 2003-09-04 03:52:38 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    48154815    }
    48164816
     4817    private static final Primitive LOG = new Primitive("log") {
     4818        public LispObject execute(LispObject arg) throws LispError
     4819        {
     4820            return log(arg);
     4821        }
     4822        public LispObject execute(LispObject number, LispObject base)
     4823            throws LispError
     4824        {
     4825            return log(number).divideBy(log(base));
     4826        }
     4827    };
     4828
     4829    private static final LispFloat log(LispObject obj) throws TypeError
     4830    {
     4831        if (obj instanceof Fixnum)
     4832            return new LispFloat(Math.log(((Fixnum)obj).getValue()));
     4833        if (obj instanceof Bignum)
     4834            return new LispFloat(Math.log(((Bignum)obj).floatValue()));
     4835        if (obj instanceof Ratio)
     4836            return new LispFloat(Math.log(((Ratio)obj).floatValue()));
     4837        if (obj instanceof LispFloat)
     4838            return new LispFloat(Math.log(((LispFloat)obj).getValue()));
     4839        throw new TypeError(obj, "number");
     4840    }
     4841
    48174842    // ### gcd-2
    48184843    private static final Primitive2 GCD_2 =
Note: See TracChangeset for help on using the changeset viewer.