source: git/factory/singext.cc @ 341696

spielwiese
Last change on this file since 341696 was 341696, checked in by Hans Schönemann <hannes@…>, 14 years ago
Adding Id property to all files git-svn-id: file:///usr/local/Singular/svn/trunk@12231 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 1.6 KB
Line 
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
16MP_INT
17gmp_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
36MP_INT
37gmp_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
56int gf_value (const CanonicalForm & f )
57{
58    InternalCF * ff = f.getval();
59    return ((long)ff) >>2; 
60}
61
62CanonicalForm
63make_cf ( const MP_INT & n )
64{
65    return CanonicalForm( CFFactory::basic( n ) );
66}
67
68CanonicalForm
69make_cf ( const MP_INT & n, const MP_INT & d, bool normalize )
70{
71    return CanonicalForm( CFFactory::rational( n, d, normalize ) );
72}
73
74CanonicalForm make_cf_from_gf ( const int z )
75{
76    return CanonicalForm(int2imm_gf(z));
77}
Note: See TracBrowser for help on using the repository browser.