示例#1
0
 public static Sexpr sin(Sexpr arg)
 {
     if (arg.isConstant())
         return new Constant(Math.Sin(arg.getValue()));
     else
         return new Sin(arg);
 }
示例#2
0
        public static Sexpr sub(Sexpr l, Sexpr r)
        {
            if(l.isConstant() && r.isConstant())
               return new Constant(l.getValue() - r.getValue());

            else if(l.isZero())
                return new Negation(r);

            else if(r.isZero())
                return l;

            else
                return new Subtraction(l,r);
        }
示例#3
0
        public static Sexpr mult(Sexpr l, Sexpr r)
        {
            if(l.isConstant() && r.isConstant())
            return new Constant(l.getValue() * r.getValue());

            else if(l.isZero() || r.isZero())
            return new Constant(0);

            else if(l.isOne())
            return r;
            else if(r.isOne())
            return l;

            else
            return new Mult(l,r);
        }
示例#4
0
 public static Sexpr neg(Sexpr tecken)
 {
     if (tecken.isConstant())
         return new Constant(-(tecken.getValue()));
     else
         return new Negation(tecken);
 }
示例#5
0
 public static Sexpr log(Sexpr arg)
 {
     if (arg.isConstant())
         return new Constant(Math.Log(arg.getValue()));
     else
         return new Log(arg);
 }
示例#6
0
 public static Sexpr exp(Sexpr arg)
 {
     if (arg.isConstant())
         return new Constant(Math.Exp(arg.getValue()));
     else
         return new Exp(arg);
 }
示例#7
0
        public static Sexpr div(Sexpr l, Sexpr r)
        {
            if(r.isZero())
            throw new CalculatorException("F�r inte dela med noll");

            else
            {
            if(l.isConstant() && r.isConstant())
                return new Constant(l.getValue() / r.getValue());

            else if(l.isZero())
                return new Constant(0);

            else
                return new Div(l,r);
            }
        }
示例#8
0
 public static Sexpr cos(Sexpr arg)
 {
     if (arg.isConstant())
         return new Constant(Math.Cos(arg.getValue()));
     else
         return new Cos(arg);
 }
示例#9
0
        public static Sexpr add(Sexpr l, Sexpr r)
        {
            if (l.isConstant() && r.isConstant())
            {
                Sexpr ret = new Constant(l.getValue() + r.getValue());

                // return new Constant(l.getValue() + r.getValue());
                return ret;
            }
            else if (l.isZero())
                return r;

            else if (r.isZero())
                return l;

            else
                return new addition(l, r);
        }