/// <summary> /// Performs the division (with remainder) of two long integer numbers. /// </summary> /// <param name="one">The first LongInt number.</param> /// <param name="two">The second LongInt number.</param> /// <param name="remainder">The reference to contain the remainder.</param> /// <returns>The result of integral division.</returns> public static LongInt <B> Div(LongInt <B> one, LongInt <B> two, out LongInt <B> remainder) { Contract.Requires <ArgumentNullException>(one != null, "one"); Contract.Requires <ArgumentNullException>(two != null, "two"); Contract.Ensures(Contract.ForAll(Contract.Result <LongInt <B> >().Digits, x => (x >= 0))); // Проверка на тупые случаи - деление на большее число или деление на единичную цифру. if (one.Length < two.Length) { remainder = one.Clone() as LongInt <B>; return(new LongInt <B>()); // zero number should be returned } if (two.Length == 1) { LongInt <B> result = new LongInt <B>(one.Length); result.Digits.AddRange(new int[one.Length]); int rem = LongIntegerMethods.DivideByInteger(LongInt <B> .BASE, result.Digits, one.Digits, two[0]); // Разберемся с negativeness. remainder = (LongInt <B>)rem; // convert the result to LongInt... result.Negative = one.Negative ^ two.Negative; remainder.Negative = one.Negative; result.DealWithZeroes(); remainder.DealWithZeroes(); return(result); } LongInt <B> res = new LongInt <B>(); res.Digits.AddRange(new int[one.Length - two.Length + 1]); remainder = new LongInt <B>(two.Length); // ----- big bada-boom! IList <int> remDigits = LongIntegerMethods.Div(LongInt <B> .BASE, res.Digits, one.Digits, two.Digits); // -------------------- remainder.Digits.AddRange(remDigits); // deal with negativeness res.Negative = one.Negative ^ two.Negative; remainder.Negative = one.Negative; // deal with zeroes res.DealWithZeroes(); remainder.DealWithZeroes(); return(res); }
public LongInt <P> getCopy(LongInt <P> num) { return(num.Clone() as LongInt <P>); }
public LongInt <P> intPart(LongInt <P> num) { return(num.Clone() as LongInt <P>); }