source: git/factory/singext.cc @ 276c3f

spielwiese
Last change on this file since 276c3f was 186402, checked in by Hans Schönemann <hannes@…>, 14 years ago
gmp stuff/factory git-svn-id: file:///usr/local/Singular/svn/trunk@12731 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 1.7 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
16void 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
36void 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
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.