예제 #1
0
        public override int Compare(CNumber other)
        {
            if (other.MyType != MyType)
            {
                throw new NotImplementedException();
            }

            CNumber_Integer o = (CNumber_Integer)other;

            int t_len = size;
            int o_len = o.size;

            if (o_len > t_len)
            {
                return(-1);
            }
            if (o_len < t_len)
            {
                return(1);
            }

            --t_len;
            while (t_len > 0 && o._Values[t_len] == _Values[t_len])
            {
                --t_len;
            }
            return(Math.Sign(_Values[t_len] - o._Values[t_len]));
        }
예제 #2
0
        //------------------------------------------------------------
        // Add a result to the output TextBox
        // returns true if the Term was added
        protected bool Add(string Term)
        {
            // write to the output
            NewEntry(Term);

            try
            {
                // let the calculation begin
                // this will throw an exception on error
                MMC.Numbers.CNumber Result = Env.Evaluate(Term);
                if (Result == null)
                {
                    throw new MMC.Calc.CTermException("could not calculate!");
                }

                //----------------------------------------------------
                // add the term to the history listbox
                AddToHistory(Term);

                //------------------------------------------------
                // and write the result to the output
                // print for all output-bases
                foreach (int Base in _OutputBase.Bases)
                {
                    NewSubEntry(Result.ToString((uint)Base), Color_Default);
                }
            }
            catch (MMC.Calc.CTermException exc)
            {
                NewSubEntry(exc.Message, Color_Error);
                return(false);
            }
            return(true);
        }
예제 #3
0
 public override CNumber xor(CNumber other)
 {
     if (other.MyType != MyType)
     {
         throw new NotImplementedException();
     }
     return(new CNumber_Double(((long)_Value) ^ ((long)((CNumber_Double)other)._Value)));
 }
예제 #4
0
 //------------------------------------------------------------
 // the little operations
 public override CNumber pow(CNumber other)
 {
     if (other.MyType != MyType)
     {
         throw new NotImplementedException();
     }
     return(new CNumber_Double(Math.Pow(_Value, ((CNumber_Double)other)._Value)));
 }
예제 #5
0
 //------------------------------------------------------------
 // which one is bigger?
 public override int Compare(CNumber other)
 {
     if (other.MyType != MyType)
     {
         throw new NotImplementedException();
     }
     return(Math.Sign(_Value - ((CNumber_Double)other)._Value));
 }
예제 #6
0
 public override bool Equals(CNumber other)
 {
     if (other.MyType != MyType)
     {
         return(false);
     }
     return(_Value == ((CNumber_Double)other)._Value);
 }
예제 #7
0
        //------------------------------------------------------------
        // general helpers

        // Sets the seconds since 1/1/19070
        public virtual void Date(CNumber year, CNumber month, CNumber day)
        {
            DateTime dt    = new DateTime(year.AsInteger, month.AsInteger, day.AsInteger);
            long     dt_s  = dt.ToFileTimeUtc();
            long     bgn_s = 0x019db1ded53e8000; // DateTime(1970, 1, 1).ToFileTimeUtc()

            long diff = dt_s - bgn_s;            // diff in 100 ns

            diff     /= 10 * 1000 * 1000;        // diff in s
            AsInteger = (int)diff;
        }
예제 #8
0
        public override CNumber rem(CNumber other)
        {
            if (other.MyType != MyType)
            {
                throw new NotImplementedException();
            }

            long result;

            Math.DivRem((long)_Value, (long)(((CNumber_Double)other)._Value), out result);
            return(new CNumber_Double(result));
        }
예제 #9
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));
 }
예제 #10
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);
        }
예제 #11
0
        public override CNumber xor(CNumber other)
        {
            if (other.MyType != MyType)
            {
                throw new NotImplementedException();
            }
            CNumber_Integer res   = new CNumber_Integer(this);
            CNumber_Integer o     = (CNumber_Integer)other;
            int             o_len = o._Values.Count;                 // the other length
            int             t_len = _Values.Count;                   // our own length
            int             len   = (t_len < o_len) ? t_len : o_len; // calc the minimum length
            int             i     = 0;                               // start with the lowest digit

            for (; i < len; i++)                                     // first handle the common digits
            {
                res._Values[i] ^= o._Values[i];
            }
            res.Trim();
            return(res);
        }
예제 #12
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!");
        }
예제 #13
0
 public abstract CNumber mul(CNumber other);
예제 #14
0
        // Sets the day in the week (0: sunday .. 6:saturday)
        public virtual void Day(CNumber year, CNumber month, CNumber day)
        {
            DateTime dt = new DateTime(year.AsInteger, month.AsInteger, day.AsInteger);

            AsInteger = (int)dt.DayOfWeek;
        }
예제 #15
0
 public abstract int Compare(CNumber other);
예제 #16
0
 public abstract CNumber and(CNumber other);
예제 #17
0
 public virtual bool Equals(CNumber other)
 {
     return(Compare(other) == 0);
 }
예제 #18
0
 public abstract CNumber or(CNumber other);
예제 #19
0
 //------------------------------------------------------------
 // the higher functions operations
 public abstract CNumber pow(CNumber a);
예제 #20
0
 public abstract CNumber rem(CNumber other);
예제 #21
0
 public abstract CNumber div(CNumber other);
예제 #22
0
 public abstract CNumber sub(CNumber other);