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