Esempio n. 1
0
 public override MMC.Numbers.CNumber Calc(CEnvironment Env)
 {
     Check();
     MMC.Numbers.CNumber res = Env.NewNumber(0.0);
     res.Day(_Terms[0].Calc(Env), _Terms[1].Calc(Env), _Terms[2].Calc(Env));
     return(res);
 }
Esempio n. 2
0
 public override MMC.Numbers.CNumber Calc(CEnvironment Env)
 {
     Check();
     MMC.Numbers.CNumber A = _Terms[0].Calc(Env).sqr();
     MMC.Numbers.CNumber B = _Terms[1].Calc(Env).sqr();
     A.add(B);
     return(A.sqrt());
 }
Esempio n. 3
0
        public override MMC.Numbers.CNumber rem(MMC.Numbers.CNumber other)
        {
            if (other.MyType != MyType)
            {
                throw new NotImplementedException();
            }

            CNumber_Integer Res = new CNumber_Integer(this);

            return(Res.Divide((CNumber_Integer)other));
        }
Esempio n. 4
0
 //------------------------------------------------------------
 // simple divide the both terms
 public override MMC.Numbers.CNumber Calc(MMC.Calc.CEnvironment Env)
 {
     if (!(_bTermA && _bTermB))
     {
         throw new CTermException("Div not initialized!");
     }
     MMC.Numbers.CNumber B = _TermB.Calc(Env);
     if (B.IsZero)
     {
         throw new CTermException("Division by zero!");
     }
     return(_TermA.Calc(Env).div(B));
 }
Esempio n. 5
0
        //------------------------------------------------------------
        // helper to create a new number
        public MMC.Numbers.CNumber NewNumber(double Value)
        {
            MMC.Numbers.CNumber res = null;
            switch (_NumberType)
            {
            case MMC.Numbers.CNumber.CNumberType.cnt_Double:
                res = new MMC.Numbers.CNumber_Double(Value);
                break;

            case MMC.Numbers.CNumber.CNumberType.cnt_Integer:
                res = new MMC.Numbers.CNumber_Integer(Value);
                break;

            default:
                break;
            }
            return(res);
        }
Esempio n. 6
0
        public override MMC.Numbers.CNumber sub(MMC.Numbers.CNumber other)
        {
            if (other.MyType != MyType)
            {
                throw new NotImplementedException();
            }
            CNumber_Integer res = new CNumber_Integer(this);

            if (_Sign != ((CNumber_Integer)other)._Sign)
            {
                res.Addition((CNumber_Integer)other);
            }
            else
            {
                res.Subtraction((CNumber_Integer)other);
            }
            return(res);
        }
Esempio n. 7
0
        // written multiplication
        public override MMC.Numbers.CNumber mul(MMC.Numbers.CNumber other)
        {
            if (other.MyType != MyType)
            {
                throw new NotImplementedException();
            }

            CNumber_Integer o   = (CNumber_Integer)other;
            int             cnt = o._Values.Count;

            // calc the different interims (could be done in parallel)
            CNumber_Integer[] Results = new CNumber_Integer[cnt];
            for (int i = 0; i < cnt; i++)
            {
                CNumber_Integer tmp = new CNumber_Integer(this);
                tmp.Multiply(o._Values[i]);
                tmp._Values.InsertRange(0, new byte[i]);
                Results[i] = tmp;
            }

            // now add them all up
            CNumber_Integer res = new CNumber_Integer(Results[0]);

            for (int i = 1; i < cnt; i++)
            {
                res.Addition(Results[i]);
            }

            //CNumber_Integer mul = (CNumber_Integer)other;
            //for (int i = mul._Values.Count - 1; i >= 0; i--)
            //{
            //    CNumber_Integer tmp = (CNumber_Integer) Clone();
            //    tmp.Multiply(mul._Values[i]);
            //    res.Insert(0);
            //    res.Addition(tmp);
            //}

            res._Sign = (_Sign != o._Sign);
            res.Trim();
            return(res);
        }
Esempio n. 8
0
        public override bool Equals(MMC.Numbers.CNumber other)
        {
            if (other.MyType != MyType)
            {
                return(false);
            }

            CNumber_Integer o = (CNumber_Integer)other;

            if (size != o.size)
            {
                return(false);
            }

            for (int i = 0; i < size; i++)
            {
                if (_Values[i] != o._Values[i])
                {
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 9
0
        //------------------------------------------------------------
        // analyse the string and return the operation
        public MMC.Calc.CTerm_Base FindOp(ref string Term)
        {
            //--------------------------------------------------------
            // make sure we have something to do
            if (Term != null)
            {
                int length = Term.Length;
                int idx    = 0;
                while (idx < length)
                {
                    char c = Term[idx];
                    if (c != ' ' && c != '\t' && c != '\n' && c != '\r')
                    {
                        break;
                    }
                    idx++;
                }
                Term = Term.Substring(idx);
            }
            if (string.IsNullOrEmpty(Term))
            {
                return(null);
            }

            //--------------------------------------------------------
            // find the match in the various operation maps
            MMC.Calc.CTerm_Base Op = _Operations.Get(Term, 0);
            if (Op != null)
            {
                Term = Term.Remove(0, Op.Name.Length);
                return(Op.Clone());
            }

            Op = _Support.Get(Term, 0);
            if (Op != null)
            {
                Term = Term.Remove(0, Op.Name.Length);
                return(Op.Clone());
            }

            Op = _Constants.Get(Term, 0);
            if (Op != null)
            {
                Term = Term.Remove(0, Op.Name.Length);
                return(Op);  // Do not clone a constant
            }

            Op = _Variables.Get(Term, 0);
            if (Op != null)
            {
                Term = Term.Remove(0, Op.Name.Length);
                return(Op);  // Do not clone a variable
            }

            //--------------------------------------------------------
            // is it a number
            MMC.Numbers.CNumber N = NewNumber(0.0);
            if (N.FromString(ref Term))
            {
                return(new MMC.Calc.Functions.CTerm_Number(N));
            }

            //--------------------------------------------------------
            // check for an assignment
            for (int pos = 1; pos < Term.Length; pos++)
            {
                Op = _Support.Get(Term, pos);
                if (Op != null && Op.Type == CTerm_Base.TTermType.Assignment)
                {
                    MMC.Calc.Functions.CTerm_Variable Var = new MMC.Calc.Functions.CTerm_Variable(Term.Substring(0, pos));
                    Term = Term.Remove(0, pos);
                    return(Var);
                }
            }

            //--------------------------------------------------------
            // nothing found so something's wrong somewhere
            throw new CTermException("Unknown Function or Variable!");
        }
Esempio n. 10
0
 public override MMC.Numbers.CNumber pow(MMC.Numbers.CNumber a)
 {
     throw new NotImplementedException();
 }
Esempio n. 11
0
 //------------------------------------------------------------
 public CTerm_Variable(string Name)
     : base(Name, TPriority.constant, TTermType.Variable)
 {
     _Value = null;
 }
Esempio n. 12
0
 //------------------------------------------------------------
 // Constructor for Constants
 public CTerm_Number(MMC.Numbers.CNumber Value)
     : base(null, Value)
 {
     _TermType = TTermType.Number;
 }
Esempio n. 13
0
 //------------------------------------------------------------
 // Constructor for Constants
 public CTerm_Const(string Name, MMC.Numbers.CNumber Value)
     : base(Name, TPriority.constant, TTermType.Constant)
 {
     _Value = Value;
 }
Esempio n. 14
0
 //------------------------------------------------------------
 public void Set(MMC.Numbers.CNumber Value)
 {
     _Value = Value.Clone();
 }