Changeset 5740


Ignore:
Timestamp:
02/10/04 14:08:58 (17 years ago)
Author:
piso
Message:

cos(), sin()

File:
1 edited

Legend:

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

    r5718 r5740  
    33 *
    44 * Copyright (C) 2002-2004 Peter Graves
    5  * $Id: Primitives.java,v 1.562 2004-02-08 16:53:13 piso Exp $
     5 * $Id: Primitives.java,v 1.563 2004-02-10 14:08:58 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    42824282
    42834283    // ### imagpart
    4284     private static final Primitive1 IMAGPART = new Primitive1("imagpart","number")
     4284    private static final Primitive1 IMAGPART = new Primitive1("imagpart", "number")
    42854285    {
    42864286        public LispObject execute(LispObject arg) throws ConditionThrowable
     
    42934293
    42944294    // ### integer-length
    4295     private static final Primitive1 INTEGER_LENGTH = new Primitive1("integer-length","integer")
     4295    private static final Primitive1 INTEGER_LENGTH =
     4296        new Primitive1("integer-length", "integer")
    42964297    {
    42974298        public LispObject execute(LispObject arg) throws ConditionThrowable
     
    43104311    };
    43114312
    4312     private static final Primitive1 COS = new Primitive1("cos","radians")
     4313    private static final Primitive1 COS = new Primitive1("cos", "radians")
    43134314    {
    43144315        public LispObject execute(LispObject arg) throws ConditionThrowable
     
    43204321    private static LispObject cos(LispObject arg) throws ConditionThrowable
    43214322    {
    4322         if (arg.realp()) {
    4323             LispFloat argf = LispFloat.coerceToFloat(arg);
    4324             return new LispFloat(Math.cos(argf.getValue()));
    4325         } else if (arg instanceof Complex) {
    4326             Complex argc = (Complex)arg;
    4327             Complex iargc = (Complex)argc.multiplyBy(Complex.getInstance(new Fixnum(0), new Fixnum(1)));
    4328             Complex c = (Complex)exp(iargc);
    4329             c = (Complex)c.add(exp(iargc.multiplyBy(new Fixnum(-1))));
    4330             c = (Complex)c.divideBy(new Fixnum(2));
    4331             return c;
    4332         }
    4333         signal(new TypeError(arg, "number"));
    4334         return NIL;
     4323        if (arg.realp())
     4324            return new LispFloat(Math.cos(LispFloat.coerceToFloat(arg).getValue()));
     4325        if (arg instanceof Complex) {
     4326            LispObject n = arg.multiplyBy(Complex.getInstance(Fixnum.ZERO,
     4327                                                              Fixnum.ONE));
     4328            LispObject result = exp(n);
     4329            result = result.add(exp(n.multiplyBy(Fixnum.MINUS_ONE)));
     4330            return result.divideBy(Fixnum.TWO);
     4331        }
     4332        return signal(new TypeError(arg, "number"));
    43354333    }
    43364334
    4337     private static final Primitive1 SIN = new Primitive1("sin","radians")
     4335    private static final Primitive1 SIN = new Primitive1("sin", "radians")
    43384336    {
    43394337        public LispObject execute(LispObject arg) throws ConditionThrowable
     
    43454343    private static LispObject sin(LispObject arg) throws ConditionThrowable
    43464344    {
    4347         if (arg.realp()) {  // return real
    4348             LispFloat argf = LispFloat.coerceToFloat(arg);
    4349             return new LispFloat(Math.sin(argf.getValue()));
    4350         } else if (arg instanceof Complex) {
    4351             Complex argc = (Complex)arg;
    4352             Complex iargc = (Complex)argc.multiplyBy(Complex.getInstance(new Fixnum(0), new Fixnum(1)));
    4353             Complex c = (Complex)exp(iargc);
    4354             c = (Complex)c.subtract(exp(iargc.multiplyBy(new Fixnum(-1))));
    4355             c = (Complex)c.divideBy((new Fixnum(2)).multiplyBy(Complex.getInstance(new Fixnum(0), new Fixnum(1))));
    4356             return c;
    4357         }
    4358         signal(new TypeError(arg, "number"));
    4359         return NIL;
     4345        if (arg.realp())
     4346            return new LispFloat(Math.sin(LispFloat.coerceToFloat(arg).getValue()));
     4347        if (arg instanceof Complex) {
     4348            LispObject n = arg.multiplyBy(Complex.getInstance(Fixnum.ZERO,
     4349                                                              Fixnum.ONE));
     4350            LispObject result = exp(n);
     4351            result = result.subtract(exp(n.multiplyBy(Fixnum.MINUS_ONE)));
     4352            return result.divideBy(Fixnum.TWO.multiplyBy(Complex.getInstance(Fixnum.ZERO,
     4353                                                                             Fixnum.ONE)));
     4354        }
     4355        return signal(new TypeError(arg, Symbol.NUMBER));
    43604356    }
    43614357
    4362     private static final Primitive1 TAN = new Primitive1("tan","radians")
     4358    private static final Primitive1 TAN = new Primitive1("tan", "radians")
    43634359    {
    43644360        public LispObject execute(LispObject arg) throws ConditionThrowable
     
    43734369    }
    43744370
    4375     private static final Primitive1 EXP = new Primitive1("exp","number")
     4371    private static final Primitive1 EXP = new Primitive1("exp", "number")
    43764372    {
    43774373        public LispObject execute(LispObject arg) throws ConditionThrowable
     
    43944390            return Complex.getInstance(resX, resY);
    43954391        }
    4396         signal(new TypeError(arg, "number"));
    4397         return NIL;
     4392        return signal(new TypeError(arg, "number"));
    43984393    }
    43994394
Note: See TracChangeset for help on using the changeset viewer.