예제 #1
0
 /// <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));
     }
 }
예제 #2
0
 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);
     }
 }
예제 #3
0
 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);
     }
 }
예제 #4
0
 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);
     }
 }
예제 #5
0
        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);
        }