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 | void gmp_numerator ( const CanonicalForm & f, mpz_ptr result ) |
---|
17 | { |
---|
18 | InternalCF * ff = f.getval(); |
---|
19 | ASSERT( ! is_imm( ff ), "illegal type" ); |
---|
20 | if ( ff->levelcoeff() == IntegerDomain ) |
---|
21 | { |
---|
22 | mpz_init_set( result, &(InternalInteger::MPI( ff )) ); |
---|
23 | ff->deleteObject(); |
---|
24 | } |
---|
25 | else if ( ff->levelcoeff() == RationalDomain ) |
---|
26 | { |
---|
27 | mpz_init_set( result, &(InternalRational::MPQNUM( ff )) ); |
---|
28 | ff->deleteObject(); |
---|
29 | } |
---|
30 | else |
---|
31 | { |
---|
32 | ASSERT( 0, "illegal type" ); |
---|
33 | } |
---|
34 | } |
---|
35 | |
---|
36 | void gmp_denominator ( const CanonicalForm & f, mpz_ptr result ) |
---|
37 | { |
---|
38 | InternalCF * ff = f.getval(); |
---|
39 | ASSERT( ! is_imm( ff ), "illegal type" ); |
---|
40 | if ( ff->levelcoeff() == IntegerDomain ) |
---|
41 | { |
---|
42 | mpz_init_set_si( result, 1 ); |
---|
43 | ff->deleteObject(); |
---|
44 | } |
---|
45 | else if ( ff->levelcoeff() == RationalDomain ) |
---|
46 | { |
---|
47 | mpz_init_set( result, &(InternalRational::MPQDEN( ff )) ); |
---|
48 | ff->deleteObject(); |
---|
49 | } |
---|
50 | else |
---|
51 | { |
---|
52 | ASSERT( 0, "illegal type" ); |
---|
53 | } |
---|
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 | } |
---|