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