//快速计算 protected static bool NumberMath2Value(char opCode, CQ_Value left, CQ_Value right, out CQ_Value returnValue) { try { returnValue = new CQ_Value(); Type retType = NumberUtil.GetReturnType_Math2Value(left.m_type, right.m_type); double leftValue = left.GetNumber(); // GetDouble(left.m_type, left.GetValue()); double rightValue = right.GetNumber(); // GetDouble(right.m_type, right.GetValue()); double finalValue; switch (opCode) { case '+': finalValue = leftValue + rightValue; break; case '-': finalValue = leftValue - rightValue; break; case '*': finalValue = leftValue * rightValue; break; case '/': finalValue = leftValue / rightValue; break; case '%': finalValue = leftValue % rightValue; break; default: throw new Exception("Invalid math operation::opCode = " + opCode); } if (NumberUtil.IsNumberType(retType)) { returnValue.SetNumber(retType, NumberUtil.ConvertNumber(finalValue, retType)); } return(true); } catch (Exception) { returnValue = CQ_Value.Null; return(false); } }
/// <summary> /// 调用这个方法必须保证类型与obj匹配,比如m_type = float,存进来的万一是int,就取不出了,所以外面就必须做好转型 /// </summary> // public void SetValue (Object obj) { // if(m_type != null){ // SetValue(m_type, obj); // }else if(m_stype != null){ // SetValue(m_stype, obj); // }else{ // if(obj == null) // _obj = null; // else // throw new Exception("不允许在无类型的情况下赋值"); // } // } //保持原有的type,而使用别的CQ_Value的值(一般用于赋值) public void UsingValue(CQ_Value val) { if (NumberUtil.IsNumberType(val.m_type)) { double d = val.GetNumber(); SetNumber(val.m_type, d); } else if (val.m_type == typeof(bool)) { bool b = val.GetBool(); SetBool(b); } else if (val.IsDelegate || val.IsDeleEvent) { _obj = val._obj; } else { SetObject(val.typeBridge, val._obj); } }
public static bool NumberMathLogic(LogicToken logicCode, CQ_Value left, CQ_Value right, out bool mathLogicSuccess) { mathLogicSuccess = true; try { double leftValue = left.GetNumber(); // GetDouble(left.m_type, left.GetValue()); double rightValue = right.GetNumber(); // GetDouble(right.m_type, right.GetValue()); switch (logicCode) { case LogicToken.equal: return(leftValue == rightValue); case LogicToken.less: return(leftValue < rightValue); case LogicToken.less_equal: return(leftValue <= rightValue); case LogicToken.greater: return(leftValue > rightValue); case LogicToken.greater_equal: return(leftValue >= rightValue); case LogicToken.not_equal: return(leftValue != rightValue); default: throw new Exception("Invalid logic operation::logicCode = " + logicCode.ToString()); } } catch (Exception) { mathLogicSuccess = false; return(false); } }