public static void UInt64BitwiseOperationsTest() { Assert.True(Bit <ulong> .Not(2) == unchecked ((ulong)~2)); Assert.True(Bit <ulong> .Or(1, 2) == (1 | 2)); Assert.True(Bit <ulong> .And(1, 2) == (1 & 2)); Assert.True(Bit <ulong> .ShiftLeft(1, 2) == (1 << 2)); Assert.True(Bit <ulong> .ShiftRight(1, 2) == (1 >> 2)); }
public static void ByteBitwiseOperationsTest() { Assert.True(Bit <byte> .Not(2) == unchecked ((byte)~2)); Assert.True(Bit <byte> .Or(1, 2) == (1 | 2)); Assert.True(Bit <byte> .And(1, 2) == (1 & 2)); Assert.True(Bit <byte> .ShiftLeft(1, 2) == (1 << 2)); Assert.True(Bit <byte> .ShiftRight(1, 2) == (1 >> 2)); }
public static void UInt64BitwiseOperationsTest() { Assert.True(Bit <ulong> .Not(2) == unchecked ((ulong)~2)); Assert.True(Bit <ulong> .Or(1, 2) == (1 | 2)); Assert.True(Bit <ulong> .And(1, 2) == (1 & 2)); Assert.True(Bit <ulong> .ShiftLeft(1, 2) == (1 << 2)); Assert.True(Bit <ulong> .ShiftRight(1, 2) == (1 >> 2)); Assert.Equal(NumericType <ulong> .MaxValue >> 1, Bit <ulong> .ShiftRight(NumericType <ulong> .MaxValue, 1)); }
protected override Expression VisitBinary(BinaryExpression node) { Visit(node.Left); var valueLeft = PopValue(); Visit(node.Right); var valueRight = PopValue(); object value = null; if (node.Method != null) { value = node.Method.Invoke(null, new object[] { valueLeft, valueRight }); PushValue(value); return(node); } switch (node.NodeType) { //四则运算 case ExpressionType.Add: value = Arithmetic.Add(valueLeft, valueRight, node.Type); break; case ExpressionType.Subtract: value = Arithmetic.Subtract(valueLeft, valueRight, node.Type); break; case ExpressionType.Multiply: value = Arithmetic.Multiply(valueLeft, valueRight, node.Type); break; case ExpressionType.Divide: value = Arithmetic.Divide(valueLeft, valueRight, node.Type); break; case ExpressionType.Modulo: value = Arithmetic.Modulo(valueLeft, valueRight, node.Type); break; //数值比较 case ExpressionType.Equal: value = ValueComparer.Equal(valueLeft, valueRight); break; case ExpressionType.NotEqual: value = ValueComparer.NotEqual(valueLeft, valueRight); break; case ExpressionType.LessThan: value = ValueComparer.LessThan(valueLeft, valueRight); break; case ExpressionType.LessThanOrEqual: value = ValueComparer.LessThanOrEqual(valueLeft, valueRight); break; case ExpressionType.GreaterThan: value = ValueComparer.GreaterThan(valueLeft, valueRight); break; case ExpressionType.GreaterThanOrEqual: value = ValueComparer.GreaterThanOrEqual(valueLeft, valueRight); break; //逻辑运算 case ExpressionType.And: case ExpressionType.AndAlso: if (valueLeft is bool && valueLeft is bool) { value = Logic.And(valueLeft, valueRight); } else { value = Bit.And(valueLeft, valueRight, node.Type); } break; case ExpressionType.Or: case ExpressionType.OrElse: if (valueLeft is bool && valueLeft is bool) { value = Logic.Or(valueLeft, valueRight); } else { value = Bit.Or(valueLeft, valueRight, node.Type); } break; case ExpressionType.ExclusiveOr: value = Bit.Xor(valueLeft, valueRight, node.Type); break; } if (value == null) { throw new NotImplementedException(node.NodeType.ToString()); } Debug.Assert(value != null); PushValue(value); return(node); }