Esempio n. 1
0
        public static BigNumber Parse(string s)
        {
            if (string.IsNullOrEmpty(s))
            {
                throw new InvalidDataException("String is null or empty");
            }
            var array = s.Split('/');

            if (array.Length > 2)
            {
                throw new InvalidDataException("Fraction is not valid, to many '/' characters");
            }
            if (array.Length == 0)
            {
                throw new InvalidDataException("Invalid fraction");
            }
            BigNumber a;

            if (array[0].Contains("."))
            {
                double d;
                if (!double.TryParse(array[0], out d))
                {
                    throw new InvalidDataException("Numerator is not a valid number");
                }
                a = new BigNumber(d);
            }
            else
            {
                BigInteger bigInt;
                if (!BigInteger.TryParse(array[0], out bigInt))
                {
                    throw new InvalidDataException("Numerator is not a valid number");
                }
                a = new BigNumber(bigInt);
            }
            if (array.Length == 1)
            {
                return(a);
            }
            BigNumber b;

            if (array[1].Contains("."))
            {
                double d;
                if (!double.TryParse(array[1], out d))
                {
                    throw new InvalidDataException("Numerator is not a valid number");
                }
                b = new BigNumber(d);
            }
            else
            {
                BigInteger bigInt;
                if (!BigInteger.TryParse(array[1], out bigInt))
                {
                    throw new InvalidDataException("Numerator is not a valid number");
                }
                b = new BigNumber(bigInt);
            }

            return(a / b);
        }
Esempio n. 2
0
 public BigNumber Subtract(BigNumber other)
 {
     return(Add(other.AdditiveInverse));
 }