[493c477] | 1 | /* emacs edit mode for this file is -*- C++ -*- */ |
---|
[2dd068] | 2 | |
---|
[16f511] | 3 | #ifdef HAVE_CONFIG_H |
---|
[e4fe2b] | 4 | #include "config.h" |
---|
[16f511] | 5 | #endif /* HAVE_CONFIG_H */ |
---|
[9d7aaa] | 6 | |
---|
[650f2d8] | 7 | #include "cf_assert.h" |
---|
[9d7aaa] | 8 | |
---|
[2dd068] | 9 | #include "cf_defs.h" |
---|
| 10 | #include "singext.h" |
---|
| 11 | #include "int_cf.h" |
---|
| 12 | #include "int_int.h" |
---|
| 13 | #include "int_rat.h" |
---|
| 14 | #include "imm.h" |
---|
| 15 | #include "cf_factory.h" |
---|
| 16 | |
---|
[ee668e] | 17 | #include <factory/cf_gmp.h> |
---|
[daa556] | 18 | |
---|
| 19 | |
---|
[8357930] | 20 | void gmp_numerator ( const CanonicalForm & f, mpz_ptr result ) |
---|
[2dd068] | 21 | { |
---|
| 22 | InternalCF * ff = f.getval(); |
---|
| 23 | ASSERT( ! is_imm( ff ), "illegal type" ); |
---|
[8357930] | 24 | if ( ff->levelcoeff() == IntegerDomain ) |
---|
| 25 | { |
---|
[a52291] | 26 | mpz_init_set( result, (InternalInteger::MPI( ff )) ); |
---|
[8357930] | 27 | ff->deleteObject(); |
---|
[2dd068] | 28 | } |
---|
[8357930] | 29 | else if ( ff->levelcoeff() == RationalDomain ) |
---|
| 30 | { |
---|
[a52291] | 31 | mpz_init_set( result, (InternalRational::MPQNUM( ff )) ); |
---|
[8357930] | 32 | ff->deleteObject(); |
---|
[2dd068] | 33 | } |
---|
[8357930] | 34 | else |
---|
| 35 | { |
---|
| 36 | ASSERT( 0, "illegal type" ); |
---|
[2dd068] | 37 | } |
---|
| 38 | } |
---|
| 39 | |
---|
[8357930] | 40 | void gmp_denominator ( const CanonicalForm & f, mpz_ptr result ) |
---|
[2dd068] | 41 | { |
---|
| 42 | InternalCF * ff = f.getval(); |
---|
| 43 | ASSERT( ! is_imm( ff ), "illegal type" ); |
---|
[8357930] | 44 | if ( ff->levelcoeff() == IntegerDomain ) |
---|
| 45 | { |
---|
| 46 | mpz_init_set_si( result, 1 ); |
---|
| 47 | ff->deleteObject(); |
---|
[2dd068] | 48 | } |
---|
[8357930] | 49 | else if ( ff->levelcoeff() == RationalDomain ) |
---|
| 50 | { |
---|
[a52291] | 51 | mpz_init_set( result, (InternalRational::MPQDEN( ff )) ); |
---|
[8357930] | 52 | ff->deleteObject(); |
---|
[2dd068] | 53 | } |
---|
[8357930] | 54 | else |
---|
| 55 | { |
---|
| 56 | ASSERT( 0, "illegal type" ); |
---|
[2dd068] | 57 | } |
---|
| 58 | } |
---|
| 59 | |
---|
[8838ab] | 60 | int gf_value (const CanonicalForm & f ) |
---|
| 61 | { |
---|
| 62 | InternalCF * ff = f.getval(); |
---|
[564e39] | 63 | return ((intptr_t)ff) >>2; |
---|
[8838ab] | 64 | } |
---|
| 65 | |
---|
[2dd068] | 66 | CanonicalForm |
---|
[a52291] | 67 | make_cf ( const mpz_ptr n ) |
---|
[2dd068] | 68 | { |
---|
[186402] | 69 | return CanonicalForm( CFFactory::basic( n ) ); |
---|
[2dd068] | 70 | } |
---|
| 71 | |
---|
| 72 | CanonicalForm |
---|
[a52291] | 73 | make_cf ( const mpz_ptr n, const mpz_ptr d, bool normalize ) |
---|
[2dd068] | 74 | { |
---|
[186402] | 75 | return CanonicalForm( CFFactory::rational( n, d, normalize ) ); |
---|
[2dd068] | 76 | } |
---|
[8838ab] | 77 | |
---|
| 78 | CanonicalForm make_cf_from_gf ( const int z ) |
---|
| 79 | { |
---|
| 80 | return CanonicalForm(int2imm_gf(z)); |
---|
| 81 | } |
---|