Beispiel #1
0
        public static S_Int operator %(S_Int a, S_Int b)
        {
            S_Int o = a / b; //divide it 'it auto rounds'

            o = a - (o * b); //take away o*b from a becaouse if o is a remainder IE a/b is not a whole number then we will subtrace the closest number to a from a so that the remainder is left IE diferance between closest rounded and beginning number
            return(o);
        }
Beispiel #2
0
        }   //8

        public static S_Int Parse(short x)
        {
            S_Int a = new S_Int();

            a.Data = x.ToString().ToCharArray();
            return(a);
        }  //16
Beispiel #3
0
        }  //64

        public static S_Int Parse(string x)
        {
            for (int pos = 0; pos < x.Length; pos++)
            {
                switch (x[pos])
                {
                case ('0'):
                case ('1'):
                case ('2'):
                case ('3'):
                case ('4'):
                case ('5'):
                case ('6'):
                case ('7'):
                case ('8'):
                case ('9'):
                    break;

                default:
                    throw new Exception("THIS IS NOT A NUMBER IS HAS WORDS");
                }
            }

            //if here x is only numbers
            S_Int o = new S_Int();

            o.Data = x.ToCharArray();
            return(o);
        } //#
Beispiel #4
0
        public static S_Int operator *(int b, S_Int a)
        {
            S_Int o = new S_Int();

            for (int x = 0; x < b; x++)
            {
                o += a;
            }
            return(o);
        }
Beispiel #5
0
        public static S_Int operator *(S_Int a, S_Int b)
        {
            S_Int o = new S_Int();

            for (long x = 0; x < b.Data.Length; x++)
            {
                o += a;
            }
            return(o);
        }
Beispiel #6
0
        public static S_Int operator /(int b, S_Int a)
        {
            S_Int o = new S_Int();

            for (long x = 0; x < a.Data.Length; x++)
            {
                if (a - o > b)
                {
                    o += b;
                }
                else
                {
                    break;
                }
            }


            return(o);
        }
Beispiel #7
0
        /// <summary>
        /// adds A and B together
        /// </summary>
        /// <param name="a">Value A</param>
        /// <param name="b">Value B</param>
        /// <returns>the result of A and B</returns>
        private static S_Int comb(S_Int a, S_Int b)
        {
            int    carry  = 0;
            string output = "*";

            for (long x = 0; x <= a.Data.Length; x++)
            {
                if (x == a.Data.Length)
                {
                    if (carry > 0)
                    {
                        output = carry.ToString() + output;//finnish up add remainder to end (sould only be 1 digit large)
                        break;
                    }
                }
                else
                {
                    int num = carry;//num is carry + db + da : d=digit a=input_a b=input_b carry=RamainderOfLast-d

                    if (b.Data.Length > x)
                    {
                        num += int.Parse(b.Data[x].ToString());
                    }
                    num += int.Parse(a.Data[x].ToString());

                    if (num >= 10)
                    {
                        num  -= 10;
                        carry = 1;
                    }
                    else
                    {
                        carry = 0;
                    }
                    output = num.ToString() + output;//add digit
                }
            }
            S_Int o = new S_Int();

            o.Data = output.Replace("*", "").ToCharArray();
            return(o);
        }
Beispiel #8
0
        /// <summary>
        /// takes B away from A
        /// </summary>
        /// <param name="a">Value A</param>
        /// <param name="b">Value B</param>
        /// <returns>the remender of A-B</returns>
        private static S_Int part(S_Int a, S_Int b)
        {
            short  carry  = 0;
            string output = "";

            for (long x = 0; x < a.Data.Length + 1; x++)
            {
                if (x == b.Data.Length)
                {
                    if (carry != 0)
                    {
                        throw new Exception("negativ numbers are not implamented yet");
                    }
                    break;
                }
                else
                {
                    short num = carry;//num is carry + db + da : d=digit a=input_a b=input_b carry=RamainderOfLast-d

                    if (b.Data.Length < x)
                    {
                        num -= short.Parse(b.Data[x].ToString());
                    }
                    num += short.Parse(a.Data[x].ToString());


                    if (num < 0)
                    {
                        num  += 10;
                        carry = -1;
                    }
                    output = num.ToString() + output;//add digit
                }
            }
            S_Int o = new S_Int();

            o.Data = output.ToCharArray();
            return(o);
        }
Beispiel #9
0
 /// <summary>
 /// Takes x away from me
 /// </summary>
 /// <param name="x">Value</param>
 public void minus(S_Int x)
 {
     Data = part(this, x).Data;
 }
Beispiel #10
0
 /// <summary>
 /// adds x to me
 /// </summary>
 /// <param name="x">Value</param>
 public void add(S_Int x)
 {
     Data = comb(this, x).Data;
 }
Beispiel #11
0
 /// <summary>
 /// same as 'me == x'
 /// </summary>
 /// <param name="x">Value</param>
 /// <returns>if the same</returns>
 public bool Equals(S_Int x)
 {
     Data = x.Data;
     return(true);
 }