public SqlNumberNode Apply(SqlNumberNode left, SqlNumberNode right) { if (left.IsNumeric || right.IsNumeric) { return(ApplyNumeric(left.AsNumeric(), right.AsNumeric())); } if (left.IsBigint || right.IsBigint) { return(ApplyBigint(left.AsBigInt(), right.AsBigInt())); } return(ApplyInt(left, right)); }
private SqlNumberNode ApplyNumeric(SqlNumberNode left, SqlNumberNode right) { switch (Operator) { case "+": return(new SqlNumberNode(left.Numeric + right.Numeric)); case "-": return(new SqlNumberNode(left.Numeric - right.Numeric)); case "*": return(new SqlNumberNode(left.Numeric * right.Numeric)); case "/": return(new SqlNumberNode(left.Numeric / right.Numeric)); case "%": return(new SqlNumberNode(left.Numeric % right.Numeric)); } throw new Exception($"Cannot apply operator {Operator} to operands of type numeric"); }
private SqlNumberNode ApplyInt(SqlNumberNode left, SqlNumberNode right) { switch (Operator) { case "+": return(new SqlNumberNode(left.Int + right.Int)); case "-": return(new SqlNumberNode(left.Int - right.Int)); case "*": return(new SqlNumberNode(left.Int * right.Int)); case "/": return(new SqlNumberNode(left.Int / right.Int)); case "%": return(new SqlNumberNode(left.Int % right.Int)); case "&": return(new SqlNumberNode(left.Int & right.Int)); case "^": return(new SqlNumberNode(left.Int ^ right.Int)); case "|": return(new SqlNumberNode(left.Int | right.Int)); } throw new Exception($"Cannot apply operator {Operator} to operands of type int"); }