public object Neg(object v, TypeDescriptor resultType) { object result; if (TryCallIntrinsicOp("op_UnaryNegation", out result, v)) { return(result); } TypeDescriptor nt = TypeDescriptor.GetTypeOf(v); EResultCategory rcat = GetResultCategory(nt); switch (rcat) { case EResultCategory.SignedIntegral: { long l = TypeConversions.ToLong(v); return(-l); } case EResultCategory.UnsignedIntegral: { throw new ArgumentException(); } case EResultCategory.FloatingPoint: { double d = TypeConversions.ToDouble(v); return(-d); } default: throw new NotImplementedException(); } }
public object Div(object v1, object v2, TypeDescriptor resultType) { object oresult; if (TryCallIntrinsicOp("op_Division", out oresult, v1, v2)) { return(oresult); } TypeDescriptor t1 = TypeDescriptor.GetTypeOf(v1); TypeDescriptor t2 = TypeDescriptor.GetTypeOf(v2); EResultCategory rcat = GetResultCategory(t1); switch (rcat) { case EResultCategory.SignedIntegral: { long l1 = TypeConversions.ToLong(v1); long l2 = TypeConversions.ToLong(v2); return(l1 / l2); } case EResultCategory.UnsignedIntegral: { ulong u1 = TypeConversions.ToULong(v1); ulong u2 = TypeConversions.ToULong(v2); return(u1 / u2); } case EResultCategory.FloatingPoint: { double d1 = TypeConversions.ToDouble(v1); double d2 = TypeConversions.ToDouble(v2); return(d1 / d2); } default: throw new NotImplementedException(); } }