source: git/factory/cf_char.cc @ a52291

spielwiese
Last change on this file since a52291 was e4fe2b, checked in by Oleksandr Motsak <motsak@…>, 13 years ago
FIX: Fixed huge BUG in cf_gmp.h CHG: starting to cleanup factory
  • 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 "cf_assert.h"
7
8#include "cf_defs.h"
9#include "canonicalform.h"
10#include "imm.h"
11#include "int_pp.h"
12#include "cf_primes.h"
13#include "cf_binom.h"
14#include "cf_util.h"
15
16static int theCharacteristic = 0;
17static int theDegree = 1;
18
19int initializeCharacteristic ()
20{
21    theCharacteristic = 0;
22    theDegree = 1;
23    return 1;
24}
25
26void setCharacteristic( int c )
27{
28    if ( c == 0 )
29    {
30        theDegree = 0;
31        CFFactory::settype( IntegerDomain );
32        theCharacteristic = 0;
33    }
34    else
35    {
36        theDegree = 1;
37        CFFactory::settype( FiniteFieldDomain );
38        theCharacteristic = c;
39        ff_big = c > cf_getSmallPrime( cf_getNumSmallPrimes()-1 );
40        if (c > 536870909) factoryError("characteristic is too large(max is 2^29)");
41        ff_setprime( c );
42        resetFPT();
43    }
44}
45
46void setCharacteristic( int c, int n )
47{
48    ASSERT( c > 1 && n > 0, "illegal characteristic" );
49    setCharacteristic( c );
50    InternalPrimePower::setPrimePower( c, n );
51    CFFactory::settype( PrimePowerDomain );
52}
53
54void setCharacteristic( int c, int n, char name )
55{
56    ASSERT( c != 0 && n > 1, "illegal GF(q)" );
57    setCharacteristic( c );
58    gf_setcharacteristic( c, n, name );
59    theDegree = n;
60    CFFactory::settype( GaloisFieldDomain );
61}
62
63int getCharacteristic()
64{
65    return theCharacteristic;
66}
67
68int getExp()
69{
70  return InternalPrimePower::getk();
71}
72
73
74int getGFDegree()
75{
76    ASSERT( theDegree > 0, "not in GF(q)" );
77    return theDegree;
78}
79
80CanonicalForm getGFGenerator()
81{
82    ASSERT( theDegree > 1, "not in GF(q)" );
83    return int2imm_gf( 1 );
84}
Note: See TracBrowser for help on using the repository browser.