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 )
254 mpz_divexact( tmp1,
_den, g );
256 mpz_divexact( tmp2,
MPQDEN( c ), g );
257 mpz_mul( d, tmp2,
_den );
258 mpz_mul( tmp2, tmp2,
_num );
259 mpz_mul( tmp1, tmp1,
MPQNUM( c ) );
260 mpz_add( n, tmp1, tmp2 );
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 )
312 mpz_divexact( tmp1,
_den, g );
314 mpz_divexact( tmp2,
MPQDEN( c ), g );
315 mpz_mul( d, tmp2,
_den );
316 mpz_mul( tmp2, tmp2,
_num );
317 mpz_mul( tmp1, tmp1,
MPQNUM( c ) );
318 mpz_sub( n, tmp2, tmp1 );
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;
367 mpz_init( tmp1 ); mpz_init( tmp2 );
369 mpz_divexact( tmp1,
_num, g1 );
371 mpz_set( tmp1,
_num );
373 mpz_divexact( tmp2,
MPQNUM( c ), g2 );
375 mpz_set( tmp2,
MPQNUM( c ) );
376 mpz_mul( n, tmp1, tmp2 );
378 mpz_divexact( tmp1,
MPQDEN( c ), g1 );
380 mpz_set( tmp1,
MPQDEN( c ) );
382 mpz_divexact( tmp2,
_den, g2 );
384 mpz_set( tmp2,
_den );
385 mpz_mul( d, tmp1, tmp2 );
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;
427 mpz_init( tmp1 ); mpz_init( tmp2 );
429 mpz_divexact( tmp1,
_num, g1 );
431 mpz_set( tmp1,
_num );
433 mpz_divexact( tmp2,
MPQDEN( c ), g2 );
435 mpz_set( tmp2,
MPQDEN( c ) );
436 mpz_mul( n, tmp1, tmp2 );
438 mpz_divexact( tmp1,
MPQNUM( c ), g1 );
440 mpz_set( tmp1,
MPQNUM( c ) );
442 mpz_divexact( tmp2,
_den, g2 );
444 mpz_set( tmp2,
_den );
445 mpz_mul( d, tmp1, tmp2 );
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 )
714 ASSERT( c != 0 || invert,
"divide by zero" );
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 )
887 mpz_init_set( res,
_num );
900 ASSERT( mpz_cmp_si(
_den, 1 ) == 0,
"illegal operation" );
901 return mpz_get_si(
_num );
911 return mpz_sgn(
_num );
InternalCF * modcoeff(InternalCF *, bool)
friend class InternalInteger
Factory's internal rationals.
InternalCF * mulcoeff(InternalCF *)
void rem(unsigned long *a, unsigned long *q, unsigned long p, int °a, int degq)
InternalCF * addsame(InternalCF *)
int comparesame(InternalCF *)
comparesame(), comparecoeff() - compare with an InternalRational.
InternalCF * mulsame(InternalCF *)
void divremcoeff(InternalCF *, InternalCF *&, InternalCF *&, bool)
InternalCF * normalize_myself()
reduce InternalRational to lowest terms
InternalCF * int2imm(long i)
void divremsame(InternalCF *, InternalCF *&, InternalCF *&)
InternalCF * addcoeff(InternalCF *)
bool divremcoefft(InternalCF *, InternalCF *&, InternalCF *&, bool)
InternalCF * dividecoeff(InternalCF *, bool)
const CanonicalForm CFMap CFMap int &both_non_zero int n
InternalCF * bextgcdsame(InternalCF *, CanonicalForm &, CanonicalForm &)
InternalCF * copyObject()
static mpz_ptr MPQDEN(const InternalCF *const c)
virtual class for internal CanonicalForm's
virtual bool isZero() const
virtual bool isOne() const
bool InternalCF::isOne, isZero () const
virtual int levelcoeff() const
InternalCF * neg()
InternalCF * InternalRational::neg ()
InternalCF * bgcdcoeff(const InternalCF *const )
Interface to generate InternalCF's over various domains from intrinsic types or mpz_t's.
InternalCF * subcoeff(InternalCF *, bool)
int comparecoeff(InternalCF *)
comparecoeff() compares the CO=a/b and the integer c using the equivalence a/b < c iff a < c*b...
InternalCF * dividesame(InternalCF *)
void print(OSTREAM &, char *)
virtual InternalCF * dividesame(InternalCF *) PVIRT_INTCF("dividesame")
InternalCF * divsame(InternalCF *)
virtual InternalCF * dividecoeff(InternalCF *, bool) PVIRT_INTCF("dividecoeff")
static InternalCF * basic(long value)
InternalCF * modulosame(InternalCF *)
static mpz_ptr MPI(const InternalCF *const c)
MPI() - return underlying mpz_t of `c'.
long imm2int(const InternalCF *const imm)
utility functions for gmp
InternalCF * bgcdsame(const InternalCF *const ) const
InternalCF * subsame(InternalCF *)
operations on immediates, that is elements of F_p, GF, Z, Q that fit into intrinsic int...
bool divremsamet(InternalCF *, InternalCF *&, InternalCF *&)
InternalCF * modulocoeff(InternalCF *, bool)
static long intgcd(long a, long b)
InternalCF * modsame(InternalCF *)
#define ASSERT(expression, message)
bool mpz_is_imm(const mpz_t mpi)
InternalCF * bextgcdcoeff(InternalCF *, CanonicalForm &, CanonicalForm &)
InternalCF * divcoeff(InternalCF *, bool)
static mpz_ptr MPQNUM(const InternalCF *const c)
InternalCF * deepCopyObject() const
Factory's internal integers.