static Bignum MultiplyUnsignedSmallFactor(Bignum old, long digit, bool sign) { int length_x = old.Length; Bignum p = new Bignum(sign, length_x + 1); old.DestructiveCopy(p); p [length_x] = (BignumDigit)0L; bignum_destructive_scale_up(p, digit); return(p.Trim()); }
static void bignum_divide_unsigned_large_denominator(Bignum numerator, Bignum denominator, out Bignum quotient, out Bignum remainder, bool qsign, bool rsign) { int length_n = numerator.Length + 1; int length_d = denominator.Length; Bignum q = new Bignum(qsign, length_n - length_d); Bignum u = new Bignum(rsign, length_n); int shift = 0; if (!(length_d > 1)) { throw new NotImplementedException(); } { BignumDigit v1 = denominator[length_d - 1]; while (v1 < (BIGNUM_RADIX / 2)) { v1 <<= 1; shift += 1; } } if (shift == 0) { numerator.DestructiveCopy(u); // bignum_destructive_copy (numerator, u); u [length_n - 1] = (BignumDigit)0; // (BIGNUM_REF (u, (length_n - 1))) = 0; throw new NotImplementedException(); // bignum_divide_unsigned_normalized (u, denominator, q); } else { Bignum v = new Bignum(false, length_d); // (bignum_allocate (length_d, 0)); numerator.DestructiveNormalization(u, shift); //bignum_destructive_normalization (numerator, u, shift); denominator.DestructiveNormalization(v, shift); //bignum_destructive_normalization (denominator, v, shift); bignum_divide_unsigned_normalized(u, v, q); //bignum_divide_unsigned_normalized (u, v, q); //BIGNUM_DEALLOCATE (v); //if (remainder != ((bignum_type*) 0)) // bignum_destructive_unnormalization (u, shift); } quotient = q.Trim(); // (bignum_trim (q)); remainder = u.Trim(); //(bignum_trim (u)); //else // BIGNUM_DEALLOCATE (u); return; }
static void bignum_divide_unsigned_large_denominator (Bignum numerator, Bignum denominator, out Bignum quotient, out Bignum remainder, bool qsign, bool rsign) { int length_n = numerator.Length + 1; int length_d = denominator.Length; Bignum q = new Bignum (qsign, length_n - length_d); Bignum u = new Bignum (rsign, length_n); int shift = 0; if (!(length_d > 1)) throw new NotImplementedException (); { BignumDigit v1 = denominator[length_d - 1]; while (v1 < (BIGNUM_RADIX / 2)) { v1 <<= 1; shift += 1; } } if (shift == 0) { numerator.DestructiveCopy (u); // bignum_destructive_copy (numerator, u); u [length_n - 1] = (BignumDigit) 0; // (BIGNUM_REF (u, (length_n - 1))) = 0; throw new NotImplementedException (); // bignum_divide_unsigned_normalized (u, denominator, q); } else { Bignum v = new Bignum (false, length_d); // (bignum_allocate (length_d, 0)); numerator.DestructiveNormalization (u, shift); //bignum_destructive_normalization (numerator, u, shift); denominator.DestructiveNormalization (v, shift); //bignum_destructive_normalization (denominator, v, shift); bignum_divide_unsigned_normalized (u, v, q); //bignum_divide_unsigned_normalized (u, v, q); //BIGNUM_DEALLOCATE (v); //if (remainder != ((bignum_type*) 0)) // bignum_destructive_unnormalization (u, shift); } quotient = q.Trim ();// (bignum_trim (q)); remainder = u.Trim(); //(bignum_trim (u)); //else // BIGNUM_DEALLOCATE (u); return; }
static Bignum MultiplyUnsignedSmallFactor (Bignum old, long digit, bool sign) { int length_x = old.Length; Bignum p = new Bignum (sign, length_x + 1); old.DestructiveCopy (p); p [length_x] = (BignumDigit) 0L; bignum_destructive_scale_up (p, digit); return p.Trim (); }