37 mpz_init_set_si(
_den, 1 );
42 mpz_init_set_si(
_num,
i );
43 mpz_init_set_si(
_den, 1 );
48 ASSERT( d != 0,
"divide by zero" );
51 mpz_init_set_si(
_num, 0 );
52 mpz_init_set_si(
_den, 1 );
56 long g =
intgcd( (
long) n, (
long) d );
59 mpz_init_set_si(
_num, -((
long)n) /
g );
60 mpz_init_set_si(
_den, -((
long)d) /
g );
64 mpz_init_set_si(
_num, n /
g );
65 mpz_init_set_si(
_den, d /
g );
72 mpz_init_set_si(
_num,
i );
73 mpz_init_set_si(
_den, 1 );
78 ASSERT( d != 0,
"divide by zero" );
81 mpz_init_set_si(
_num, 0 );
82 mpz_init_set_si(
_den, 1 );
89 mpz_init_set_si(
_num, -n /
g );
90 mpz_init_set_si(
_den, -d /
g );
94 mpz_init_set_si(
_num, n /
g );
95 mpz_init_set_si(
_den, d /
g );
103 ASSERT( 0,
"fatal error" );
116 mpz_init_set_si(
_den, 1 );
135 mpz_init_set( dummy_num,
_num );
136 mpz_init_set( dummy_den,
_den );
143 char * str =
new char[mpz_sizeinbase(
_num, 10 ) + 2];
144 str = mpz_get_str( str, 10,
_num );
147 str =
new char[mpz_sizeinbase(
_den, 10 ) + 2];
148 str = mpz_get_str( str, 10,
_den );
188 mpz_init_set( dummy,
_num );
206 mpz_init_set( dummy,
_den );
222 mpz_init_set( dummy_num,
_num );
223 mpz_init_set( dummy_den,
_den );
224 mpz_neg( dummy_num, dummy_num );
239 mpz_init(
g ); mpz_init( n ); mpz_init( d );
242 if ( mpz_cmp_si(
g, 1 ) == 0 )
262 if ( mpz_cmp_si(
g, 1 ) != 0 )
264 mpz_divexact( n, n,
g );
265 mpz_divexact( d, d,
g );
272 if ( mpz_cmp_si( d, 1 ) == 0 )
297 mpz_init(
g ); mpz_init( n ); mpz_init( d );
300 if ( mpz_cmp_si(
g, 1 ) == 0 )
320 if ( mpz_cmp_si(
g, 1 ) != 0 )
322 mpz_divexact( n, n,
g );
323 mpz_divexact( d, d,
g );
330 if ( mpz_cmp_si( d, 1 ) == 0 )
352 mpz_init( n ); mpz_init( d );
362 mpz_init( g1 ); mpz_init( g2 );
365 bool g1is1 = mpz_cmp_si( g1, 1 ) == 0;
366 bool g2is1 = mpz_cmp_si( g2, 1 ) == 0;
386 mpz_clear(
tmp1 ); mpz_clear(
tmp2 );
387 mpz_clear( g1 ); mpz_clear( g2 );
390 if ( mpz_cmp_si( d, 1 ) == 0 )
421 mpz_init( n ); mpz_init( d );
422 mpz_init( g1 ); mpz_init( g2 );
425 bool g1is1 = mpz_cmp_si( g1, 1 ) == 0;
426 bool g2is1 = mpz_cmp_si( g2, 1 ) == 0;
446 mpz_clear(
tmp1 ); mpz_clear(
tmp2 );
447 mpz_clear( g1 ); mpz_clear( g2 );
449 if ( mpz_cmp_si( d, 0 ) < 0 )
454 if ( mpz_cmp_si( d, 1 ) == 0 )
519 mpz_t dummy1, dummy2;
520 mpz_init( dummy1 ); mpz_init( dummy2 );
523 int result = mpz_cmp( dummy1, dummy2 );
524 mpz_clear( dummy1 ); mpz_clear( dummy2 );
542 mpz_init_set_si( dummy,
imm2int( c ) );
543 mpz_mul( dummy, dummy,
_den );
574 mpz_mul_ui( n,
_den, -cc );
575 mpz_sub( n,
_num, n );
579 mpz_mul_ui( n,
_den, cc );
580 mpz_add( n,
_num, n );
589 mpz_add( n,
_num, n );
591 mpz_init_set( d,
_den );
616 mpz_init_set( d,
_den );
617 mpz_init_set( n,
_num );
628 mpz_mul_ui( n,
_den, -cc );
632 mpz_mul_ui( n,
_den, cc );
634 mpz_sub( n, n,
_num );
636 mpz_sub( n,
_num, n );
644 mpz_sub( n, n,
_num );
646 mpz_sub( n,
_num, n );
648 mpz_init_set( d,
_den );
666 mpz_init_set_si( n, cc );
674 mpz_gcd(
g, n,
_den );
675 if ( mpz_cmp_si(
g, 1 ) == 0 )
677 mpz_mul( n, n,
_num );
678 mpz_init_set( d,
_den );
682 mpz_divexact( n, n,
g );
683 mpz_mul( n, n,
_num );
685 mpz_divexact( d,
_den,
g );
689 if ( mpz_cmp_si( d, 1 ) == 0 )
723 mpz_init_set_si( n, cc );
724 mpz_mul( n, n,
_den );
725 mpz_init_set( d,
_num );
729 mpz_init_set_si( d, cc );
730 mpz_mul( d, d,
_den );
731 mpz_init_set( n,
_num );
740 mpz_mul( n, n,
_den );
741 mpz_init_set( d,
_num );
746 mpz_mul( d, d,
_den );
747 mpz_init_set( n,
_num );
750 if ( mpz_cmp_si( d, 0 ) < 0 )
757 if ( mpz_cmp_si(
g, 1 ) != 0 )
759 mpz_divexact( d, d,
g );
760 mpz_divexact( n, n,
g );
769 if ( mpz_cmp_si( d, 1 ) == 0 )
865 if ( mpz_cmp_si(
g, 1 ) != 0 )
871 if ( mpz_cmp_si(
_den, 0 ) < 0 )
876 if ( mpz_cmp_si(
_den, 1 ) == 0 )
900 ASSERT( mpz_cmp_si(
_den, 1 ) == 0,
"illegal operation" );
901 return mpz_get_si(
_num );
911 return mpz_sgn(
_num );
#define ASSERT(expression, message)
Interface to generate InternalCF's over various domains from intrinsic types or mpz_t's.
static InternalCF * basic(int value)
virtual class for internal CanonicalForm's
InternalCF * copyObject()
virtual InternalCF * dividecoeff(InternalCF *, bool) PVIRT_INTCF("dividecoeff")
virtual bool isZero() const
virtual void print(OSTREAM &, char *) PVIRT_VOID("print")
virtual int levelcoeff() const
virtual InternalCF * invert()
virtual InternalCF * dividesame(InternalCF *) PVIRT_INTCF("dividesame")
virtual bool isOne() const
bool InternalCF::isOne, isZero () const
static mpz_ptr MPI(const InternalCF *const c)
MPI() - return underlying mpz_t of ācā.
void divremcoeff(InternalCF *, InternalCF *&, InternalCF *&, bool)
InternalCF * divsame(InternalCF *)
InternalCF * bextgcdcoeff(InternalCF *, CanonicalForm &, CanonicalForm &)
InternalCF * subcoeff(InternalCF *, bool)
InternalCF * normalize_myself()
reduce InternalRational to lowest terms
int comparesame(InternalCF *)
comparesame(), comparecoeff() - compare with an InternalRational.
friend class InternalInteger
InternalCF * modsame(InternalCF *)
InternalCF * addsame(InternalCF *)
InternalCF * bgcdcoeff(const InternalCF *const)
bool divremcoefft(InternalCF *, InternalCF *&, InternalCF *&, bool)
bool divremsamet(InternalCF *, InternalCF *&, InternalCF *&)
InternalCF * bextgcdsame(InternalCF *, CanonicalForm &, CanonicalForm &)
InternalCF * bgcdsame(const InternalCF *const) const
InternalCF * mulsame(InternalCF *)
InternalCF * modcoeff(InternalCF *, bool)
InternalCF * deepCopyObject() const
void divremsame(InternalCF *, InternalCF *&, InternalCF *&)
InternalCF * divcoeff(InternalCF *, bool)
InternalCF * dividecoeff(InternalCF *, bool)
InternalCF * dividesame(InternalCF *)
InternalCF * neg()
InternalCF * InternalRational::neg ()
InternalCF * addcoeff(InternalCF *)
static mpz_ptr MPQDEN(const InternalCF *const c)
InternalCF * modulosame(InternalCF *)
int comparecoeff(InternalCF *)
comparecoeff() compares the CO=a/b and the integer c using the equivalence a/b < c iff a < c*b.
InternalCF * subsame(InternalCF *)
static mpz_ptr MPQNUM(const InternalCF *const c)
InternalCF * modulocoeff(InternalCF *, bool)
InternalCF * mulcoeff(InternalCF *)
utility functions for gmp
bool mpz_is_imm(const mpz_t mpi)
operations on immediates, that is elements of F_p, GF, Z, Q that fit into intrinsic int,...
static long imm2int(const InternalCF *const imm)
static InternalCF * int2imm(long i)
Factory's internal integers.
static long intgcd(long a, long b)
Factory's internal rationals.
void rem(unsigned long *a, unsigned long *q, unsigned long p, int °a, int degq)