Ejemplo n.º 1
0
 public void TestModulo()
 {
     Assert.AreEqual(AtomHelper.NumberFromComplex(1), Eval("(modulo 13 4)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(3), Eval("(modulo -13 4)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(-3), Eval("(modulo 13 -4)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(-1), Eval("(modulo -13 -4)"));
 }
Ejemplo n.º 2
0
 public void TestRemainder()
 {
     Assert.AreEqual(AtomHelper.NumberFromComplex(1), Eval("(remainder 13 4)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(-1), Eval("(remainder -13 4)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(1), Eval("(remainder 13 -4)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(-1), Eval("(remainder -13 -4)"));
 }
Ejemplo n.º 3
0
 public void TestMinMax()
 {
     Assert.AreEqual(AtomHelper.NumberFromComplex(3), Eval("(max 0 1 2 3)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(3), Eval("(max -1 1 2 3)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(0), Eval("(min 0 1 2 3)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(-1), Eval("(min -1 1 2 3)"));
 }
Ejemplo n.º 4
0
 public void TestTruncate()
 {
     Assert.AreEqual(AtomHelper.NumberFromComplex(1), Eval("(truncate 1.5)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(1), Eval("(truncate 1)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(2000), Eval("(truncate 2000.00001)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(0), Eval("(truncate -0.9)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(-99), Eval("(truncate -99.5)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(-100), Eval("(truncate -100)"));
 }
Ejemplo n.º 5
0
 public void TestCeiling()
 {
     Assert.AreEqual(AtomHelper.NumberFromComplex(2), Eval("(ceiling 1.5)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(1), Eval("(ceiling 1)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(2001), Eval("(ceiling 2000.00001)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(0), Eval("(ceiling -0.9)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(-99), Eval("(ceiling -99.5)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(-100), Eval("(ceiling -100)"));
 }
Ejemplo n.º 6
0
 public void TestFloor()
 {
     Assert.AreEqual(AtomHelper.NumberFromComplex(1), Eval("(floor 1.5)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(1), Eval("(floor 1)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(2000), Eval("(floor 2000.00001)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(-1), Eval("(floor -0.9)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(-100), Eval("(floor -99.5)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(-100), Eval("(floor -100)"));
 }
Ejemplo n.º 7
0
        public static ISExpression Modulo(IEnumerable <ISExpression> args)
        {
            var array = args.Cast <NumberAtom>().ToArray();
            var a     = array[0].Val;
            var b     = array[1].Val;

            var c = (a.RealModulo(b) + b).RealModulo(b);

            return(AtomHelper.NumberFromComplex(c));
        }
Ejemplo n.º 8
0
        public static ISExpression Remainder(IEnumerable <ISExpression> args)
        {
            var array = args.Cast <NumberAtom>().ToArray();
            var a     = array[0];
            var b     = array[1];

            var c = a.Val.RealModulo(b.Val);

            return(AtomHelper.NumberFromComplex(c));
        }
Ejemplo n.º 9
0
        public static ISExpression Gcd(IEnumerable <ISExpression> args)
        {
            if (!args.Any())
            {
                return(AtomHelper.NumberFromComplex(0));
            }

            var nums = args.Cast <NumberAtom>().Select(a => a.Val).ToArray();

            return(AtomHelper.NumberFromComplex(GCD(nums).RealAbs()));
        }
Ejemplo n.º 10
0
        public static ISExpression Lcm(IEnumerable <ISExpression> args)
        {
            if (args.Count() == 0)
            {
                return(AtomHelper.NumberFromComplex(1));
            }

            var nums = args.Cast <NumberAtom>().Select(a => a.Val).ToArray();

            return(AtomHelper.NumberFromComplex(LCM(nums).RealAbs()));
        }
Ejemplo n.º 11
0
        private static NumberAtom Sum(this IEnumerable <NumberAtom> ee)
        {
            Complex sum = Complex.CreateExactReal(0);

            foreach (var e in ee)
            {
                sum = sum + e.Val;
            }

            return(AtomHelper.NumberFromComplex(sum));
        }
Ejemplo n.º 12
0
        private static NumberAtom Multiply(this IEnumerable <NumberAtom> ee)
        {
            Complex m = Complex.CreateExactReal(1);

            foreach (var e in ee)
            {
                m = m * e.Val;
            }

            return(AtomHelper.NumberFromComplex(m));
        }
Ejemplo n.º 13
0
 public void TestRound()
 {
     Assert.AreEqual(AtomHelper.NumberFromComplex(2), Eval("(round 1.5)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(1), Eval("(round 1)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(2000), Eval("(round 2000.00001)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(-1), Eval("(round -0.9)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(-100), Eval("(round -99.5)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(-100), Eval("(round -100)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(4), Eval("(round 4.4)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(4), Eval("(round 4.5)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(5), Eval("(round 4.6)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(-4), Eval("(round -4.4)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(-4), Eval("(round -4.5)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(-5), Eval("(round -4.6)"));
 }
Ejemplo n.º 14
0
        public static ISExpression Div(IEnumerable <ISExpression> args)
        {
            if (args.Count() == 1)
            {
                return(AtomHelper.NumberFromComplex(Complex.CreateExactReal(1) / (args.First() as NumberAtom).Val));
            }

            var v = (args.First() as NumberAtom).Val;

            foreach (var a in args.Cast <NumberAtom>().Skip(1))
            {
                v = v / a.Val;
            }

            return(AtomHelper.NumberFromComplex(v));
        }
Ejemplo n.º 15
0
        public static ISExpression Minus(IEnumerable <ISExpression> args)
        {
            if (args.Count() == 1)
            {
                return(AtomHelper.NumberFromComplex(-((NumberAtom)args.First()).Val));
            }

            var v = (args.First() as NumberAtom).Val;

            foreach (var a in args.Cast <NumberAtom>().Skip(1))
            {
                v = v - a.Val;
            }

            return(AtomHelper.NumberFromComplex(v));
        }
Ejemplo n.º 16
0
        public static ISExpression Quotient(IEnumerable <ISExpression> args)
        {
            var array = args.Cast <NumberAtom>().ToArray();
            var a     = array[0];
            var b     = array[1];

            var c = a.Val / b.Val;

            if (c.Real.IsInteger())
            {
                return(AtomHelper.NumberFromComplex(c));
            }
            else
            {
                return(AtomHelper.NumberFromComplex(c.RealTruncate()));
            }
        }
Ejemplo n.º 17
0
        public static ISExpression Max(IEnumerable <ISExpression> args)
        {
            var nums = args.Cast <NumberAtom>().Select(n => n.Val);

            return(AtomHelper.NumberFromComplex(nums.Max()));
        }
Ejemplo n.º 18
0
 public void TestQuotient()
 {
     Assert.AreEqual(AtomHelper.NumberFromComplex(5), Eval("(quotient 5 1)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(3), Eval("(quotient 13 4)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(-3), Eval("(quotient -13 4)"));
 }
Ejemplo n.º 19
0
 public void TestGcd()
 {
     Assert.AreEqual(AtomHelper.NumberFromComplex(4), Eval("(gcd 32 -36 32)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(32), Eval("(gcd 32)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(0), Eval("(gcd)"));
 }
Ejemplo n.º 20
0
 public static ISExpression Round(IEnumerable <ISExpression> args)
 {
     return(AtomHelper.NumberFromComplex(args.Cast <NumberAtom>().First().Val.RealRound()));
 }
Ejemplo n.º 21
0
 public void TestLcm()
 {
     Assert.AreEqual(AtomHelper.NumberFromComplex(288), Eval("(lcm 32 -36)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(32), Eval("(lcm 32)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(1), Eval("(lcm)"));
 }
Ejemplo n.º 22
0
 public void TestAbs()
 {
     Assert.AreEqual(AtomHelper.NumberFromComplex(3), Eval("(abs 3)"));
     Assert.AreEqual(AtomHelper.NumberFromComplex(3), Eval("(abs -3)"));
 }