/// <summary> /// Overflow safe addition of two number values. /// /// Will not overflow but instead widen the type as necessary. </summary> /// <param name="a"> left-hand operand </param> /// <param name="b"> right-hand operand </param> /// <returns> a + b </returns> public static NumberValue OverflowSafeAdd(NumberValue a, NumberValue b) { if (a is IntegralValue && b is IntegralValue) { return(OverflowSafeAdd(a.LongValue(), b.LongValue())); } else { return(a.Plus(b)); } }
public virtual NumberValue DivideBy(NumberValue numberValue) { if (numberValue is IntegralValue) { return(DividedBy(numberValue.LongValue())); } else if (numberValue is FloatingPointValue) { return(DividedBy(numberValue.DoubleValue())); } else { throw new System.ArgumentException("Cannot divide by " + numberValue); } }
public virtual NumberValue Times(NumberValue numberValue) { if (numberValue is IntegralValue) { return(Times(numberValue.LongValue())); } else if (numberValue is FloatingPointValue) { return(Times(numberValue.DoubleValue())); } else { throw new System.ArgumentException("Cannot multiply with " + numberValue); } }
public virtual NumberValue Minus(NumberValue numberValue) { if (numberValue is IntegralValue) { return(Minus(numberValue.LongValue())); } else if (numberValue is FloatingPointValue) { return(Minus(numberValue.DoubleValue())); } else { throw new System.ArgumentException("Cannot subtract " + numberValue); } }
public static long TransformToLong(object value) { if (value == null) { throw new CypherTypeException("Expected a numeric value but got null", null); } if (value is NumberValue) { NumberValue number = ( NumberValue )value; return(number.LongValue()); } if (value is Number) { Number number = ( Number )value; return(number.longValue()); } throw new CypherTypeException(string.Format("Expected a numeric value but got {0}", value.ToString()), null); }