public static CountSystem operator *(CountSystem inCSfirst, CountSystem inCSsecond) { CountSystem TestCS = new CountSystem(inCSfirst.myOrder); CountSystem retCS = new CountSystem(inCSfirst.myOrder); CountSystem inSecond = inCSsecond; if (inCSfirst.myOrder != inCSsecond.myOrder) { inSecond = GetNewOrder(inCSfirst.myOrder, inCSsecond); } for (int i = 0; i < inSecond.MyValue.Count; ++i) { TestCS.SetValue(inCSfirst); for (int ii = 0; ii < TestCS.MyValue.Count; ++ii) { TestCS.MyValue[ii] *= inSecond.MyValue[i]; } TestCS.Normalize(); TestCS.SelfTenPow(i); retCS.SelfSum(TestCS); } return(retCS); }
public void SelfMul(CountSystem inCS) { CountSystem TestCS = new CountSystem(myOrder); CountSystem retCS = new CountSystem(myOrder); CountSystem inSecond = inCS; if (myOrder != inCS.myOrder) { inSecond = GetNewOrder(myOrder, inCS); } for (int i = 0; i < inSecond.MyValue.Count; ++i) { TestCS.SetValue(this); for (int ii = 0; ii < TestCS.MyValue.Count; ++ii) { TestCS.MyValue[ii] *= inSecond.MyValue[i]; } TestCS.Normalize(); TestCS.SelfTenPow(i); retCS.SelfSum(TestCS); } MyValue = retCS.MyValue; }
public static CountSystem GetNewOrder(int inOrder, CountSystem inCS) { if (inOrder > 45000) { inOrder = 45000; } if (inOrder < 2) { inOrder = 2; } CountSystem newOne = new CountSystem(inOrder); CountSystem retCS = new CountSystem(inOrder); for (int i = 0; i < inCS.MyValue.Count; ++i) { newOne.MyValue.Clear(); newOne.MyValue.Add(inCS.MyValue[i]); for (int ii = 0; ii < i; ++ii) { newOne.MultByInt(inCS.myOrder); } retCS.SelfSum(newOne); } return(retCS); }
public override bool Equals(object obj) { CountSystem TestCS = obj as CountSystem; if (TestCS == null) { return(false); } CountSystem inSecond = TestCS; if (myOrder != inSecond.myOrder) { inSecond = GetNewOrder(myOrder, TestCS); } if (MyValue.Count != inSecond.MyValue.Count) { return(false); } for (int i = 0; i < MyValue.Count; ++i) { if (MyValue[i] != inSecond.MyValue[i]) { return(false); } } return(true); }
public static void Main() { CountSystem testCS = new CountSystem(256, 97384793); Console.WriteLine(testCS.ToString()); testCS.MyOrder = 26; Console.WriteLine(testCS.ToString()); testCS.MyOrder = 256; Console.WriteLine(testCS.ToString()); Console.ReadLine(); }
public static bool operator >=(CountSystem inCSfirst, CountSystem inCSsecond) { CountSystem inSecond = inCSsecond; if (inCSfirst.myOrder != inCSsecond.myOrder) { inSecond = GetNewOrder(inCSfirst.myOrder, inCSsecond); } if (inCSfirst.MyValue.Count > inSecond.MyValue.Count) { return(inCSfirst.MyValue[inCSfirst.MyValue.Count - 1] > 0); } if (inCSfirst.MyValue.Count < inSecond.MyValue.Count) { return(inSecond.MyValue[inSecond.MyValue.Count - 1] < 0); } for (int i = inCSfirst.MyValue.Count - 1; i >= 0; --i) { if (inCSfirst.MyValue[i] == inSecond.MyValue[i]) { continue; } if (inCSfirst.MyValue[i] > inSecond.MyValue[i]) { return(true); } if (inCSfirst.MyValue[i] < inSecond.MyValue[i]) { return(false); } } return(true); }
public void SetValue(CountSystem inCS) { CountSystem localCS = inCS; if (myOrder != inCS.myOrder) { localCS = GetNewOrder(myOrder, inCS); } MyValue.Clear(); if (MyValue.Capacity < localCS.MyValue.Count) { MyValue.Capacity = localCS.MyValue.Count; } for (int i = 0; i < localCS.MyValue.Count; ++i) { MyValue.Add(localCS.MyValue[i]); } }
public static CountSystem operator -(CountSystem inCSfirst, CountSystem inCSsecond) { CountSystem retCS = new CountSystem(inCSfirst.myOrder); retCS.MyValue.Clear(); CountSystem inSecond = inCSsecond; if (inCSfirst.myOrder != inCSsecond.myOrder) { inSecond = GetNewOrder(inCSfirst.myOrder, inCSsecond); } for (int i = 0; i < inCSfirst.MyValue.Count && i < inSecond.MyValue.Count; ++i) { retCS.MyValue.Add(inCSfirst.MyValue[i] - inSecond.MyValue[i]); } if (inCSfirst.MyValue.Count > inSecond.MyValue.Count) { for (int i = inSecond.MyValue.Count; i < inCSfirst.MyValue.Count; ++i) { retCS.MyValue.Add(inCSfirst.MyValue[i]); } } if (inCSfirst.MyValue.Count < inSecond.MyValue.Count) { for (int i = inCSfirst.MyValue.Count; i < inSecond.MyValue.Count; ++i) { retCS.MyValue.Add(-inSecond.MyValue[i]); } } retCS.Normalize(); return(retCS); }
public void SelfSub(CountSystem inCS) { CountSystem localCS = inCS; if (myOrder != inCS.myOrder) { localCS = GetNewOrder(myOrder, inCS); } for (int i = 0; i < MyValue.Count && i < localCS.MyValue.Count; ++i) { MyValue[i] -= localCS.MyValue[i]; } if (MyValue.Count < localCS.MyValue.Count) { for (int i = MyValue.Count; i < localCS.MyValue.Count; ++i) { MyValue.Add(-localCS.MyValue[i]); } } Normalize(); }
public void SelfDiv(CountSystem inCS) { CountSystem inSecond = inCS; if (myOrder != inCS.myOrder) { inSecond = GetNewOrder(myOrder, inCS); } CountSystem retCS = new CountSystem(myOrder); CountSystem testCS = new CountSystem(myOrder); CountSystem localCS = new CountSystem(myOrder); for (int i = 1; i < inSecond.MyValue.Count; ++i) { testCS.MyValue.Add(MyValue[MyValue.Count - inSecond.MyValue.Count + i]); } for (int i = MyValue.Count - inSecond.MyValue.Count; i >= 0; --i) { testCS.MyValue.Insert(0, MyValue[i]); if (testCS < inSecond) { retCS.MyValue.Add(0); continue; } else { int Min = 1; int Max = myOrder; while (Max - Min > 1) { int Mid = (Max + Min) / 2; localCS.SetValue(inSecond); localCS.MultByInt(Mid); if (localCS <= testCS) { Min = Mid; if (localCS == testCS) { break; } } else { Max = Mid; } } localCS.SetValue(inSecond); localCS.MultByInt(Min); testCS.SelfSub(localCS); retCS.MyValue.Add(Min); } } retCS.MyValue.Reverse(); retCS.Normalize(); MyValue = retCS.MyValue; }
public static CountSystem operator /(CountSystem inCSfirst, CountSystem inCSsecond) { CountSystem inSecond = inCSsecond; if (inCSfirst.myOrder != inCSsecond.myOrder) { inSecond = GetNewOrder(inCSfirst.myOrder, inCSsecond); } CountSystem retCS = new CountSystem(inCSfirst.myOrder); CountSystem testCS = new CountSystem(inCSfirst.myOrder); CountSystem localCS = new CountSystem(inCSfirst.myOrder); for (int i = 1; i < inSecond.MyValue.Count; ++i) { testCS.MyValue.Add(inCSfirst[inCSfirst.MyValue.Count - inSecond.MyValue.Count + i]); } for (int i = inCSfirst.MyValue.Count - inSecond.MyValue.Count; i >= 0; --i) { testCS.MyValue.Insert(0, inCSfirst.MyValue[i]); if (testCS < inSecond) { retCS.MyValue.Add(0); continue; } else { int Min = 1; int Max = inCSfirst.myOrder; int Mid = (Max + Min) / 2; while (Max - Min > 1) { Mid = (Max + Min) / 2; localCS.SetValue(inSecond); localCS.MultByInt(Mid); if (localCS <= testCS) { Min = Mid; if (localCS == testCS) { break; } } else { Max = Mid; } } retCS.MyValue.Add(Min); localCS.SetValue(inSecond); localCS.MultByInt(Min); testCS.SelfSub(localCS); } } retCS.MyValue.Reverse(); retCS.Normalize(); return(retCS); }
public CountSystem(CountSystem inCS) { myOrder = inCS.myOrder; SetValue(inCS.MyValue); }