コード例 #1
0
 protected bool Equals(MathArithDesc other)
 {
     return(Equals(_type, other._type) && _arith == other._arith);
 }
コード例 #2
0
ファイル: MathArithType.cs プロジェクト: lanicon/nesper
        /// <summary>
        ///     Returns number cruncher for the target coercion type.
        /// </summary>
        /// <param name="operation">Arithmetic operation.</param>
        /// <param name="coercedType">target type</param>
        /// <param name="typeOne">the LHS type</param>
        /// <param name="typeTwo">the RHS type</param>
        /// <param name="isIntegerDivision">false for division returns double, true for using standard integer division</param>
        /// <param name="isDivisionByZeroReturnsNull">false for division-by-zero returns infinity, true for null</param>
        /// <param name="optionalMathContext">math context or null</param>
        /// <returns>number cruncher</returns>
        public static Computer GetComputer(
            MathArithTypeEnum operation,
            Type coercedType,
            Type typeOne,
            Type typeTwo,
            bool isIntegerDivision,
            bool isDivisionByZeroReturnsNull,
            MathContext optionalMathContext)
        {
            coercedType = coercedType.GetBoxedType();
            if (coercedType != typeof(double?) &&
                coercedType != typeof(float?) &&
                coercedType != typeof(long?) &&
                coercedType != typeof(int?) &&
                coercedType != typeof(decimal?) &&
                coercedType != typeof(BigInteger?) &&
                coercedType != typeof(short?) &&
                coercedType != typeof(byte))
            {
                throw new ArgumentException(
                          "Expected base numeric type for computation result but got type " + coercedType);
            }

            if (coercedType.IsDecimal())
            {
                return(MakeDecimalComputer(
                           operation,
                           typeOne,
                           typeTwo,
                           isDivisionByZeroReturnsNull,
                           optionalMathContext));
            }

            if (coercedType.IsBigInteger())
            {
                return(MakeBigIntegerComputer(
                           operation,
                           typeOne,
                           typeTwo));
            }

            if (operation != MathArithTypeEnum.DIVIDE)
            {
                var key      = new MathArithDesc(coercedType, operation);
                var computer = computers.Get(key);
                if (computer == null)
                {
                    throw new ArgumentException(
                              "Could not determine process or type " + operation + " type " + coercedType);
                }

                return(computer);
            }

            if (!isIntegerDivision)
            {
                //return new DivideDecimal(isDivisionByZeroReturnsNull);
                return(new DivideDouble(isDivisionByZeroReturnsNull));
            }

            if (coercedType == typeof(decimal?))
            {
                return(new DivideDecimal(isDivisionByZeroReturnsNull));
            }

            if (coercedType == typeof(double?))
            {
                return(new DivideDouble(isDivisionByZeroReturnsNull));
            }

            if (coercedType == typeof(float?))
            {
                return(new DivideFloat());
            }

            if (coercedType == typeof(long?))
            {
                return(new DivideLong());
            }

            if (coercedType == typeof(int?))
            {
                return(new DivideInt());
            }

            throw new ArgumentException("Could not determine process or type " + operation + " type " + coercedType);
        }