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