Ejemplo n.º 1
0
        public void Should_sum_big_numbers_correctly(string x, string y, string z)
        {
            Int256 i1 = Int256.Parse(x);
            Int256 i2 = Int256.Parse(y);

            Int256 i3 = i1 + i2;

            ("0x" + i3.ToString("X32")).Should().Be(z);
        }
Ejemplo n.º 2
0
        public void Should_multiply_correctly(int x, int y, int z)
        {
            var i1 = (Int256)x;
            var i2 = (Int256)y;

            Int256 i3 = i1 * i2;

            ((int)i3).Should().Be(z);
            i3.ToString().Should().Be(z.ToString(CultureInfo.InvariantCulture));
        }
Ejemplo n.º 3
0
        public void Should_leftShift_correctly(string x, string y, string z)
        {
            //
            // X >> Y should = z
            //
            Int256 i1       = Int256.Parse(x);
            int    shifthBy = int.Parse(y);
            Int256 i3       = i1 << shifthBy;

            ("0x" + i3.ToString("X32")).Should().Be(z);
        }
Ejemplo n.º 4
0
        public static void Main(string[] args)
        {
            InitializeNumbers(K);
            foreach (var no in Numbers)
            {
                foreach (var digit in no)
                {
                    Console.Write(digit + "");
                }
                Console.WriteLine("+");
            }

            stopwatch.Start();
            for (int i = 0; i < K; i += 2)
            {
                int newI = i;
                int newJ = i + 1;
                Tasks.Add(Task.Factory.StartNew(() => Process(newI, newJ)));
            }
            Task.WaitAll(Tasks.ToArray());
            while (!Queue.IsEmpty)
            {
                Tuple <Int256, int> enqueuedItem;
                Queue.TryDequeue(out enqueuedItem);
                if (enqueuedItem != null)
                {
                    Result[enqueuedItem.Item2] += enqueuedItem.Item1;
                }
            }
            bool carry          = false;
            int  carryMagnitude = 0;

            for (int i = N - 1; i >= 0; i--)
            {
                //Console.WriteLine(Result[i]);
                if (carry)
                {
                    Result[i] += carryMagnitude;
                }
                if (Result[i] > 9 && i != 0)
                {
                    //Console.WriteLine("####:" + Result[i]);
                    carry = true;
                    Int256 t  = Result[i];
                    var    cm = int.Parse(t.ToString()[0].ToString());
                    while (t >= 10)
                    {
                        t /= 10;
                    }

                    //carryMagnitude = t%10;
                    carryMagnitude = cm;
                    //Console.WriteLine("cm:" + carryMagnitude);
                    Result[i] %= 10;
                }
                else
                {
                    carry          = false;
                    carryMagnitude = 0;
                }
            }
            stopwatch.Stop();
            for (int i = 0; i < N; i++)
            {
                Console.Write("-");
            }
            Console.WriteLine("=");
            foreach (var r in Result)
            {
                Console.Write(r + "");
            }
            Console.WriteLine("\nTime elapsed: {0}", stopwatch.ElapsedMilliseconds);
            Console.WriteLine();
            Console.WriteLine(Check() ? "OK" : "Not OK");
        }