Ejemplo n.º 1
0
 private static RealNumber createNbr(string val)
 {
     double nbr;
     var isNbr = double.TryParse(val, out nbr);
     var realNbr = new RealNumber(nbr);
     return isNbr ? realNbr : null;
 }
Ejemplo n.º 2
0
        public void equalsDouble_should_return_false_if_not_same_value()
        {
            // Given
            SUT = new RealNumber(5.1);

            // Then
            Assert.IsFalse(SUT.Equals(1.1));
        }
Ejemplo n.º 3
0
        public void equalInt_should_return_false_if_other_value()
        {
            // Given
            SUT = new RealNumber(5);

            // Then
            Assert.IsFalse(SUT.Equals(1));
        }
Ejemplo n.º 4
0
        public void equalsDouble_should_return_true_if_same_value()
        {
            // Given
            SUT = new RealNumber(5.1);

            // Then
            Assert.IsTrue(SUT.Equals(5.1));
        }
Ejemplo n.º 5
0
        public void equalsInt_should_return_false_if_value_is_double()
        {
            // Given
            SUT = new RealNumber(5.1);

            // Then
            Assert.IsFalse(SUT.Equals(5));
        }
Ejemplo n.º 6
0
        public void equalsInt_should_return_true_if_same()
        {
            // Given
            SUT = new RealNumber(5);

            // Then
            Assert.IsTrue(SUT.Equals(5));
        }
Ejemplo n.º 7
0
        public void constructor_should_set_number()
        {
            // When
            SUT = new RealNumber(1.5);

            // Then
            Assert.AreEqual(1.5, SUT.Value);
        }
Ejemplo n.º 8
0
        public void constructor_should_set_evaluateAgainst_nbr()
        {
            // Given
            var nbr = new RealNumber(1);

            // When
            SUT = new LessThan(new RealNumber(5), nbr);

            // Then
            Assert.AreSame(nbr, SUT.EvaluateAgainst);
        }
Ejemplo n.º 9
0
        public void contructor_should_set_right_number()
        {
            // Given
            var nbr = new RealNumber(1);

            // When
            SUT = new Equals(new RealNumber(2), nbr);

            // Then
            Assert.AreSame(nbr, SUT.Right);
        }
Ejemplo n.º 10
0
        public void fullConstructor_should_set_the_number()
        {
            // Given
            var nbr = new RealNumber(1);

            // When
            SUT = new Variable("a", nbr);

            // Then
            Assert.AreSame(nbr, SUT.Value);
        }
Ejemplo n.º 11
0
        public void contructor_should_set_left_number()
        {
            // Given
            var nbr = new RealNumber(1);

            // When
            SUT = new Equals(nbr, new RealNumber(2));

            // Then
            Assert.AreSame(nbr, SUT.Left);
        }
Ejemplo n.º 12
0
        public void getRealNumber_should_return_itself()
        {
            // Given
            SUT = new RealNumber(5.3);

            // When
            var result = SUT.GetRealNumber();

            // Then
            Assert.AreSame(SUT, result);
        }
Ejemplo n.º 13
0
 public void Teardown()
 {
     SUT = null;
 }
Ejemplo n.º 14
0
 public void GetRealTest()
 {
     _testVar = _testVar.getReal(1);
     Assert.Equal(1, _testVar.Real);
 }
Ejemplo n.º 15
0
        private EvaluationResult EvaluateFloats(RealNumber left, OperatorExpression op, RealNumber right)
        {
            switch (op.Token.Lexeme)
            {
            case "+": return(new EvaluationResult(EvaluationType.Float, left + right));

            case "-": return(new EvaluationResult(EvaluationType.Float, left - right));

            case "*": return(new EvaluationResult(EvaluationType.Float, left * right));

            case "/": return(new EvaluationResult(EvaluationType.Float, left / right));

            case ">": return(new EvaluationResult(EvaluationType.Boolean, left > right));

            case "<": return(new EvaluationResult(EvaluationType.Boolean, left < right));

            case "=": return(new EvaluationResult(EvaluationType.Boolean, left == right));

            case "!=": return(new EvaluationResult(EvaluationType.Boolean, left != right));

            case ">=": return(new EvaluationResult(EvaluationType.Boolean, left >= right));

            case "<=": return(new EvaluationResult(EvaluationType.Boolean, left <= right));

            default: throw new Exception("Unexpected operator: " + op.Token.Lexeme);
            }
        }
Ejemplo n.º 16
0
 public PretCumparare(RealNumber pc)
 {
     pretc = pc;
 }
Ejemplo n.º 17
0
 public StackOperation(RealNumber value, BinaryOperation operation)
 {
     Value     = value;
     Operation = operation;
     attribute = OperationAttribute.Get(operation);
 }
Ejemplo n.º 18
0
 public RealNumber Perform(RealNumber value)
 {
     return(Value.Apply(Operation, value));
 }
Ejemplo n.º 19
0
 public void Setup()
 {
     SUT = new RealNumber(0.0);
 }
Ejemplo n.º 20
0
        public void toSTring_should_return_the_double_value()
        {
            // Given
            SUT = new RealNumber(5.1);

            // When
            var result = SUT.ToString();

            // Then
            Assert.AreEqual("5.1", result);
        }
Ejemplo n.º 21
0
        public void TestAll()
        {
            for (int digits = 1; digits < 100; digits++)
            {
                RealNumber b_one = new RealNumber(2L, digits);
                RealNumber log1 = RealNumber.Zero, log2 = RealNumber.Zero;
                Parallel.Invoke(
                    () =>
                {
                    log1 = b_one.GetLog();
                },
                    () =>
                {
                    log2 = b_one.GetTaylorLog();
                });
                string log1String = log1.ToString();
                string log2String = log2.ToString();
                int    diffs      = differences(log2String, log1String);
                if (diffs > 0)
                {
                    File.WriteAllText("L1MILD.txt", log1String);
                    File.WriteAllText("L1MILT.txt", log2String);
                    Assert.IsTrue(false);
                }
            }
            //IntegerNumber zzz = new IntegerNumber(0L);
            //string ssttrr = zzz.ToString();
            bool ok = true;
            //testMultiplicationSpeed();

            RealNumber    ten     = new RealNumber(10, 1000);
            RealNumber    logTen  = ten.GetLog();
            RealNumber    tenExp1 = logTen.GetExp();
            RealNumber    tenExp2 = logTen.GetTaylorExp();
            IntegerNumber i1      = IntegerNumber.One << 100000;
            IntegerNumber ia      = i1.Sqrt();
            IntegerNumber ib      = i1.InverseSqrt();

            RealNumber ssqrt10   = ten.GetRealDirectSqrt();
            RealNumber sqrt10    = ten.GetSqrt();
            RealNumber invSqrt10 = ten.GetInverseSqrt();
            RealNumber one1      = sqrt10 * invSqrt10;

            ok &= (one1 - 1).IsZero;

            IntegerNumber int10 = IntegerNumber.Pow(10, 19 * 5000);
            IntegerNumber t1    = int10.Inverse();
            IntegerNumber t2    = (IntegerNumber.One << (int10.Digits * 128)) / int10;

            ok &= t1 == t2;
            IntegerNumber t3 = int10.InverseSqrt();
            IntegerNumber t4 = ((IntegerNumber.One << (int10.Digits * 96 * 2)) / int10).Sqrt();

            ok &= t3 == t4;

            ok &= Fourier235RealUnitTest.FFTUnitTest();
            ok &= Fourier235RealUnitTest.DCTUnitTest();
            ok &= Fourier235DoubleUnitTest.FFTUnitTest();
            ok &= Fourier235DoubleUnitTest.DCTUnitTest();
            ok &= Fourier235UnitTest.FFTUnitTest();
            ok &= Fourier235UnitTest.DCTUnitTest();

            ok &= RealNumbersUnitTest.ComplexArcTanSinCosUnitTest();
            ok &= RealNumbersUnitTest.NumericIntegerOperationsUnitTest();

            ok &= RealNumbersUnitTest.SqrtUnitTest();
            ok &= MemoryUnitTest.UnitTest(1001);
            ok &= CarrylessMultiplication.UnitTest(1001);

            int        decimalDigits = 10100;
            int        qwords        = (int)Math.Ceiling(Math.Log(10, 2) * decimalDigits / 64);
            RealNumber pi            = RealNumber.Zero;
            RealNumber e             = RealNumber.Zero;
            RealNumber one           = new RealNumber(1L, qwords);
            var        computePITime = AsmX64Operations.MeasureTime(() =>
            {
                pi = RealNumber.GetPI(qwords);
            });
            var computeETime = AsmX64Operations.MeasureTime(() =>
            {
                e = one.GetExp();
            });
            string pivalue           = "";
            string evalue            = "";
            var    baseConvertTimePI = AsmX64Operations.MeasureTime(() =>
            {
                pivalue = pi.ToString();
            });
            var baseConvertTimeE = AsmX64Operations.MeasureTime(() =>
            {
                evalue = e.ToString();
            });

            File.WriteAllText(@"..\pi10k.txt", pivalue);
            File.WriteAllText(@"..\e_10k.txt", evalue);

            //MessageBox.Show(
            //    "Compute PI Time: " + computePITime.ToString() + "\r\n" +
            //    "Compute E  Time: " + computeETime.ToString() + "\r\n" +
            //    "base convert time PI: " + baseConvertTimePI.ToString() + "\r\n" +
            //    "base convert time E : " + baseConvertTimeE.ToString() + "\r\n",
            //    "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);

            var no0 = new RealNumber(1L << 62, 2048 / 64);
            var no1 = no0.GetExp();
            var no2 = no1.GetLog();

            ok &= (no2 - no0).IsZero;

            ulong[] xx = Enumerable.Repeat(ulong.MaxValue, 1024 * 100).ToArray();
            ulong[] yy = Enumerable.Repeat(ulong.MaxValue, 1024 * 100).ToArray();
            ulong[] zz = Enumerable.Repeat((ulong)0, 1024 * 200).ToArray();
            AsmX64Operations.FastestMultiplication(xx, yy, zz, xx.Length);
            if (zz[0] != 1 || zz[zz.Length / 2 - 1] != 0 || zz[zz.Length / 2] + 2 != 0 || zz[zz.Length - 1] + 1 != 0)
            {
                ok = false;
            }

            ok &= RealNumbersUnitTest.UnitTest(1001);
            ok &= FourierReal.UnitTest(10012);
            ok &= FourierMultiplication.UnitTest();
            ok &= IntegerNumberUnitTest.UnitTest();
            ok &= FourierMultiplication.UnitTestBigMul(1001);
            ok &= FastIntegerUnitTest.UnitTest();
            ok &= FourierMultiplication.UnitTest(1001);
            ok &= AsmX64Operations.ECCUnitTest();
            ok &= AsmX64Operations.UnitTest();
            ok &= HeapUnitTest.UnitTest();
            ok &= FourierTransform.FFTUnitTest();
            ok &= AccurateSummation.UnitTest();
            ok &= BinarySearchUnitTest.UnitTest();
            ok &= AVLTree <int> .UnitTest();

            ok &= AVLTreeSorted <int> .UnitTest();

            Assert.IsTrue(ok);
        }