Esempio n. 1
0
    public override Number Mul(Number rhs)
    {
        // java NullPointerException
        if(rhs == null) throw new NullReferenceException("rhs is null");

        // java getClass()
        if(this.GetType() != rhs.GetType())
        {
          // java ClassCastException
          throw new InvalidCastException("rhs has illegal type");
        }

        Number2 cast = (Number2) rhs;

        return new Number2(BigInteger.Multiply(val, cast.val));
    }
Esempio n. 2
0
        public static Number Calculate(IBinaryOperandCalculator cal, Number n1, Number n2)
        {
            if (n1 == null || n2 == null)
            {
                return 0;
            }
            switch (n1.TypeCode)
            {
                case NumberTypeCode.Int32:
                    return cal.Calculate((int)n1, (int)n2);

                case NumberTypeCode.Int64:
                    return cal.Calculate((long)n1, (long)n2);

                case NumberTypeCode.BigInteger:
                    return cal.Calculate((BigInteger)n1, (BigInteger)n2);

                case NumberTypeCode.Double:
                case NumberTypeCode.Decimal:
                case NumberTypeCode.BigDecimal:
                    return cal.Calculate((BigDecimal)n1, (BigDecimal)n2);
            }
            throw new ArgumentException("unsupported add calculate: " + n1.GetType());
        }
Esempio n. 3
0
    public override int CompareTo(Number rhs)
    {
        // java NullPointerException
        if(rhs == null) throw new NullReferenceException("rhs is null");

        // java getClass()
        if(this.GetType() != rhs.GetType())
        {
          // java ClassCastException
          throw new InvalidCastException("rhs has illegal type");
        }

        Number2 cast = (Number2) rhs;

        return val.CompareTo(cast.val);
    }