13#undef DEBUG_LONGINTEGER_DIVISION
14#undef DEBUG_LONGINTEGER_COMPARE
17namespace layer2_discreta {
20static void subtract_signless(longinteger &x, longinteger &y, longinteger &z);
21static int do_division(longinteger& r, longinteger *d);
38 s.str().copy(p, l, 0);
60 cout <<
"longinteger::copy constructor for object: "
90 delete (
char *)
s_rep();
114#ifdef PRINT_WITH_TYPE
115 ost <<
"(LONGINTEGER, ";
117 if (
s_rep() == NULL) {
124 for (i = l - 1; i >= 0; i--) {
127#ifdef LONGINTEGER_PRINT_DOTS
133#ifdef PRINT_WITH_TYPE
165 cout <<
"longinteger::allocate() s_kind() != LONGINTEGER\n";
171 for (i = 0; i < l; i++) {
172 s_p(i) = p[l - 1 - i] -
'0';
181 cout <<
"longinteger::allocate_internal() s_kind() != LONGINTEGER\n";
186 for (i = 0; i < len; i++) {
196 cout <<
"longinteger::allocate_empty() s_kind() != LONGINTEGER\n";
203 for (i = 0; i < len; i++) {
213 for (i = l - 1; i > 0; i--) {
226 cout <<
"longinteger::compare_with() s_kind() != LONGINTEGER\n";
231 cout <<
"longinteger::compare_with() "
232 "b is neither longinteger nor integer\n";
252#ifdef DEBUG_LONGINTEGER_COMPARE
253 cout <<
"longinteger::compare_with_unsigned() returns " << r <<
"\n";
263 int la, lb, l, i, d1, d2;
268#ifdef DEBUG_LONGINTEGER_COMPARE
269 cout <<
"longinteger::compare_with_unsigned()\n";
270 cout <<
"la=" << la <<
" lb=" << lb << endl;
273 for (i = l - 1; i >= 0; i--) {
282#ifdef DEBUG_LONGINTEGER_COMPARE
283 cout <<
"i=" << i <<
"d1=" << d1 <<
"d2=" << d2 << endl;
299 cout <<
"longinteger::mult_to() this is not a longinteger\n";
310 cout <<
"longinteger::mult_to() x is not a longinteger\n";
327 for (lb = 0; lb < X.
s_len(); lb++) {
330 for (la = 0; la <
s_len(); la++) {
331 c1 =
s_p(la) * cb + carry + Y.
s_p(la + lb);
333 cout <<
"longinteger:mult_to() error: c1 >= 100\n";
337 Y.
s_p(la + lb) = c1 % 10;
341 cout <<
"longinteger:mult_to() error: "
342 "carry && Y.s_p(lb + s_len()) != 0\n";
356 cout <<
"longinteger::invert_to() this is not a longinteger\n";
359 cout <<
"longinteger::invert_to() not yet implemented\n";
366 int len, sign_a, sign_b, cmp_a_b, l;
367 char ca, cb, c1, carry;
370 cout <<
"longinteger::add_to() this is not a longinteger\n";
381 cout <<
"longinteger::add_to() x is not a longinteger\n";
389 if ((sign_a && sign_b) || (!sign_a && !sign_b)) {
398 subtract_signless(X, *
this, Y);
402 else if (cmp_a_b > 0) {
405 subtract_signless(*
this, X, Y);
418 for (l = 0; l < len; l++) {
427 c1 = ca + cb + carry;
452 for (l = 0; l < len; l++) {
473 cout <<
"longinteger::negate_to() this not an integer\n";
510 snprintf(str, 1000,
"%d", z);
557 int d = (int)
s_p(0);
564 int d = (int)
s_p(0);
572 cout <<
"longinteger::compare_with_euclidean "
573 "s_kind() != LONGINTEGER\n";
578 cout <<
"longinteger::compare_with_euclidean "
579 "b is neither longinteger nor integer\n";
598 cout <<
"longinteger::integral_division "
599 "this is not a longinteger\n";
610 cout <<
"longinteger::integral_division "
611 "x is not a longinteger\n";
616 int len, sign_x, sign_r, i, l1, l, idx;
644 for (i = 0; i < 10; i++) {
645#ifdef DEBUG_LONGINTEGER_DIVISION
646 cout <<
"i = " << i <<
" ";
649#ifdef DEBUG_LONGINTEGER_DIVISION
650 cout <<
"r1 = " << r1 <<
" ";
653#ifdef DEBUG_LONGINTEGER_DIVISION
654 cout <<
"d[i] = " << d[i] <<
" ";
657#ifdef DEBUG_LONGINTEGER_DIVISION
658 cout <<
"dm[i] = " << dm[i] << endl;
668 for (l = 0; l < len; l++) {
671#ifdef DEBUG_LONGINTEGER_DIVISION
672 cout <<
"r1 = " << r1 << endl;
677 for ( ; l1 >= 0; l1--) {
678#ifdef DEBUG_LONGINTEGER_DIVISION
679 cout <<
"dividing r1=" << r1 << endl;
681 idx = do_division(r1, d);
682#ifdef DEBUG_LONGINTEGER_DIVISION
683 cout <<
"do_division, idx = " << idx << endl;
684 cout <<
"Q[" << l1 <<
"]=" << idx << endl;
687 Q.
s_p(l1) = (char) idx;
688#ifdef DEBUG_LONGINTEGER_DIVISION
689 cout <<
"calling r2.add()" << endl;
692#ifdef DEBUG_LONGINTEGER_DIVISION
693 cout <<
"r2=" << r2 << endl;
701 len = r2.
s_len() + 1;
703 for (l = 0; l < r2.
s_len(); l++) {
704 r1.
s_p(l + 1) = r2.
s_p(l);
722 for (i = 9; i >= 0; i--) {
723#ifdef DEBUG_LONGINTEGER_DIVISION
724 cout <<
"do_division, i = " << i <<
" r=" << r <<
" d[i]=" << d[i] << endl;
730 cout <<
"longinteger do_division() not found\n";
737 cout <<
"longinteger::square_root_floor "
738 "this is not a longinteger\n";
749 cout <<
"longinteger::square_root_floor "
750 "no square root, the number is negative\n";
764 for (l = 0; l < len; l++) {
768 for (l = len - 1; l >= 0; l--) {
769 for (c1 = 9; c1 >= 0; c1--) {
814 l = s.str().length();
815 p =
new char [l + 1];
816 s.str().copy(p, l, 0);
871 int f_v = (verbose_level >= 1);
877 cout <<
"s_0 = " << s << endl;
878 for (i = 1; i <= m - 2; i++) {
884 cout <<
"s_" << i <<
" = " << s << endl;
DISCRETA base class. All DISCRETA classes are derived from this class.
longinteger & as_longinteger()
void add(discreta_base &x, discreta_base &y)
void mult(discreta_base &x, discreta_base &y)
longinteger & change_to_longinteger()
void swap(discreta_base &a)
void modulo(discreta_base &p)
void copyobject(discreta_base &x)
discreta_base & power_int(int l)
discreta_base & power_longinteger(longinteger &l)
DISCRETA class for integers of arbitrary magnitude.
void negate_to(discreta_base &x)
void divide_out_int(int d)
int compare_with(discreta_base &b)
std::ostream & print(std::ostream &)
int retract_to_integer_if_possible(integer &x)
void allocate_empty(int len)
void integral_division(discreta_base &x, discreta_base &q, discreta_base &r, int verbose_level)
longinteger & operator=(const discreta_base &x)
void freeself_longinteger()
int compare_with_unsigned(longinteger &b)
void allocate_internal(int sign, int len, const char *p)
void mult_to(discreta_base &x, discreta_base &y)
int invert_to(discreta_base &x)
int compare_with_euclidean(discreta_base &b)
void copyobject_to(discreta_base &x)
void add_to(discreta_base &x, discreta_base &y)
void settype_longinteger()
void square_root_floor(discreta_base &x)
LONGINTEGER_REPRESENTATION * s_rep()
void normalize_representation()
int Lucas_test_Mersenne(int m, int verbose_level)
void allocate(int sign, const char *p)
longinteger & Fermat(int n)
longinteger & Mersenne(int n)
#define LONGINTEGER_DIGITS_FOR_DOT
@ LONGINTEGER
LONGINTEGER.
the orbiter library for the classification of combinatorial objects
DISCRETA internal class to represent long integers.
LONGINTEGER_REPRESENTATION * longinteger_rep