source: git/factory/singext.cc @ 362fc67

spielwiese
Last change on this file since 362fc67 was 362fc67, checked in by Martin Lee <martinlee84@…>, 12 years ago
chg: remove $Id$
  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[493c477]1/* emacs edit mode for this file is -*- C++ -*- */
[2dd068]2
[e4fe2b]3#include "config.h"
[9d7aaa]4
[650f2d8]5#include "cf_assert.h"
[9d7aaa]6
[2dd068]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
[ee668e]15#include <factory/cf_gmp.h>
[daa556]16
17
[8357930]18void gmp_numerator ( const CanonicalForm & f, mpz_ptr result )
[2dd068]19{
20    InternalCF * ff = f.getval();
21    ASSERT( ! is_imm( ff ), "illegal type" );
[8357930]22    if ( ff->levelcoeff() == IntegerDomain )
23    {
[a52291]24        mpz_init_set( result, (InternalInteger::MPI( ff )) );
[8357930]25        ff->deleteObject();
[2dd068]26    }
[8357930]27    else  if ( ff->levelcoeff() == RationalDomain )
28    {
[a52291]29        mpz_init_set( result, (InternalRational::MPQNUM( ff )) );
[8357930]30        ff->deleteObject();
[2dd068]31    }
[8357930]32    else
33    {
34        ASSERT( 0, "illegal type" );
[2dd068]35    }
36}
37
[8357930]38void gmp_denominator ( const CanonicalForm & f, mpz_ptr result )
[2dd068]39{
40    InternalCF * ff = f.getval();
41    ASSERT( ! is_imm( ff ), "illegal type" );
[8357930]42    if ( ff->levelcoeff() == IntegerDomain )
43    {
44        mpz_init_set_si( result, 1 );
45        ff->deleteObject();
[2dd068]46    }
[8357930]47    else  if ( ff->levelcoeff() == RationalDomain )
48    {
[a52291]49        mpz_init_set( result, (InternalRational::MPQDEN( ff )) );
[8357930]50        ff->deleteObject();
[2dd068]51    }
[8357930]52    else
53    {
54        ASSERT( 0, "illegal type" );
[2dd068]55    }
56}
57
[8838ab]58int gf_value (const CanonicalForm & f )
59{
60    InternalCF * ff = f.getval();
[8357930]61    return ((long)ff) >>2;
[8838ab]62}
63
[2dd068]64CanonicalForm
[a52291]65make_cf ( const mpz_ptr n )
[2dd068]66{
[186402]67    return CanonicalForm( CFFactory::basic( n ) );
[2dd068]68}
69
70CanonicalForm
[a52291]71make_cf ( const mpz_ptr n, const mpz_ptr d, bool normalize )
[2dd068]72{
[186402]73    return CanonicalForm( CFFactory::rational( n, d, normalize ) );
[2dd068]74}
[8838ab]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.