public override IResultValue Evaluate() { IResultValue res = Operand.Evaluate(); if (!((double)res.ToDecimal()).IsInteger(8)) { throw new EvaluationException(this, "Cannot use floating-point types in factorial calculation."); } return(new ResultNumberReal((decimal)MathPlus.Probability.Factorial(res.ToInteger()))); }
public override IResultValue Evaluate() { IResultValue res1 = First.Evaluate(); IResultValue res2 = Second.Evaluate(); if (!((double)res1.ToDecimal()).IsInteger(8) || !((double)res2.ToDecimal()).IsInteger(8)) { throw new EvaluationException(this, "Cannot use floating-point types in modulus calculation."); } return(new ResultNumberReal((decimal)(res1.ToInteger() % res2.ToInteger()))); }
public override IResultValue Evaluate() { IResultValue list = List.Evaluate(); IResultValue index = Index.Evaluate(); if (index.Type != MathType.Integer) { throw new EvaluationException(this, "Ordinal index must be integer."); } if (list.Type != MathType.List) { throw new EvaluationException(this, "Ordinal access can only be used on a list."); } return(new ResultNumberReal(list.ToList()[(int)index.ToInteger()])); }
public override IResultValue Evaluate() { string str = First.Evaluate().ToString(); IResultValue countIRV = Second.Evaluate(); if (countIRV.Type != MathType.Integer) { throw new EvaluationException("That's no integer...."); } int count = (int)countIRV.ToInteger(); string res = ""; for (int i = 0; i < count; i++) { res += str; } return(new ResultString(res)); }