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)")); }
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)")); }
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)")); }
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)")); }
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)")); }
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)")); }
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)); }
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)); }
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())); }
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())); }
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)); }
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)); }
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)")); }
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)); }
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)); }
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())); } }
public static ISExpression Max(IEnumerable <ISExpression> args) { var nums = args.Cast <NumberAtom>().Select(n => n.Val); return(AtomHelper.NumberFromComplex(nums.Max())); }
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)")); }
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)")); }
public static ISExpression Round(IEnumerable <ISExpression> args) { return(AtomHelper.NumberFromComplex(args.Cast <NumberAtom>().First().Val.RealRound())); }
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)")); }
public void TestAbs() { Assert.AreEqual(AtomHelper.NumberFromComplex(3), Eval("(abs 3)")); Assert.AreEqual(AtomHelper.NumberFromComplex(3), Eval("(abs -3)")); }