Beispiel #1
0
        private static void getStringRepresentation(IntegerNumber x, int base10Digits, StringBuilder result)
        {
            if (base10Digits <= 18)
            {
                string value = x.ToLong.ToString();
                int    diff  = value.Length - base10Digits;
                if (diff != 0)
                {
                    if (diff < 0)
                    {
                        value = "".PadLeft(-diff, '0') + value;
                    }
                    else
                    {
                        value = value.Remove(0, diff);
                    }
                }
                result.Append(value);
                return;
            }
            int           secondHalfDigits = (base10Digits + 1) / 2;
            IntegerNumber half = IntegerNumber.Pow(10, secondHalfDigits);
            IntegerNumber reminder, quotient = IntegerNumber.DivRem(x, half, out reminder);

            getStringRepresentation(quotient, base10Digits - secondHalfDigits, result);
            getStringRepresentation(reminder, secondHalfDigits, result);
        }
Beispiel #2
0
        public static IntegerNumber operator /(IntegerNumber number1, long number2)
        {
            long          remainder;
            IntegerNumber quotient = IntegerNumber.DivRem(number1, number2, out remainder);

            return(quotient);
        }
Beispiel #3
0
        public static IntegerNumber operator %(IntegerNumber number1, IntegerNumber number2)
        {
            IntegerNumber remainder, quotient = IntegerNumber.DivRem(number1, number2, out remainder);

            return(remainder);
        }