source: git/factory/singext.cc @ 17a710

spielwiese
Last change on this file since 17a710 was 362fc67, checked in by Martin Lee <martinlee84@…>, 12 years ago
chg: remove $Id$
  • Property mode set to 100644
File size: 1.7 KB
Line 
1/* emacs edit mode for this file is -*- C++ -*- */
2
3#include "config.h"
4
5#include "cf_assert.h"
6
7#include "cf_defs.h"
8#include "singext.h"
9#include "int_cf.h"
10#include "int_int.h"
11#include "int_rat.h"
12#include "imm.h"
13#include "cf_factory.h"
14
15#include <factory/cf_gmp.h>
16
17
18void gmp_numerator ( const CanonicalForm & f, mpz_ptr result )
19{
20    InternalCF * ff = f.getval();
21    ASSERT( ! is_imm( ff ), "illegal type" );
22    if ( ff->levelcoeff() == IntegerDomain )
23    {
24        mpz_init_set( result, (InternalInteger::MPI( ff )) );
25        ff->deleteObject();
26    }
27    else  if ( ff->levelcoeff() == RationalDomain )
28    {
29        mpz_init_set( result, (InternalRational::MPQNUM( ff )) );
30        ff->deleteObject();
31    }
32    else
33    {
34        ASSERT( 0, "illegal type" );
35    }
36}
37
38void gmp_denominator ( const CanonicalForm & f, mpz_ptr result )
39{
40    InternalCF * ff = f.getval();
41    ASSERT( ! is_imm( ff ), "illegal type" );
42    if ( ff->levelcoeff() == IntegerDomain )
43    {
44        mpz_init_set_si( result, 1 );
45        ff->deleteObject();
46    }
47    else  if ( ff->levelcoeff() == RationalDomain )
48    {
49        mpz_init_set( result, (InternalRational::MPQDEN( ff )) );
50        ff->deleteObject();
51    }
52    else
53    {
54        ASSERT( 0, "illegal type" );
55    }
56}
57
58int gf_value (const CanonicalForm & f )
59{
60    InternalCF * ff = f.getval();
61    return ((long)ff) >>2;
62}
63
64CanonicalForm
65make_cf ( const mpz_ptr n )
66{
67    return CanonicalForm( CFFactory::basic( n ) );
68}
69
70CanonicalForm
71make_cf ( const mpz_ptr n, const mpz_ptr d, bool normalize )
72{
73    return CanonicalForm( CFFactory::rational( n, d, normalize ) );
74}
75
76CanonicalForm make_cf_from_gf ( const int z )
77{
78    return CanonicalForm(int2imm_gf(z));
79}
Note: See TracBrowser for help on using the repository browser.