source: git/factory/cf_char.cc @ 35a153

spielwiese
Last change on this file since 35a153 was 35a153, checked in by Hans Schoenemann <hannes@…>, 5 years ago
opt: setCharacteristic
  • Property mode set to 100644
File size: 1.4 KB
Line 
1/* emacs edit mode for this file is -*- C++ -*- */
2
3/**
4 * @file cf_char.cc
5 *
6 * getting and setting the characteristic of a finite field
7**/
8
9#include "config.h"
10
11
12#include "cf_assert.h"
13
14#include "cf_defs.h"
15#include "canonicalform.h"
16#include "imm.h"
17#include "cf_primes.h"
18#include "cf_util.h"
19
20STATIC_VAR int theCharacteristic = 0;
21STATIC_VAR int theDegree = 1;
22
23void setCharacteristic( int c )
24{
25    if ( c == 0 )
26    {
27        theDegree = 0;
28        CFFactory::settype( IntegerDomain );
29        theCharacteristic = 0;
30    }
31    else
32    {
33        theDegree = 1;
34        CFFactory::settype( FiniteFieldDomain );
35        ff_big = c > cf_getSmallPrime( cf_getNumSmallPrimes()-1 );
36        if (c!=theCharacteristic)
37        {
38          if (c > 536870909) factoryError("characteristic is too large(max is 2^29)");
39          ff_setprime( c );
40        }
41        theCharacteristic = c;
42    }
43}
44
45void setCharacteristic( int c, int n, char name )
46{
47    ASSERT( c != 0 && n > 1, "illegal GF(q)" );
48    setCharacteristic( c );
49    gf_setcharacteristic( c, n, name );
50    theDegree = n;
51    CFFactory::settype( GaloisFieldDomain );
52}
53
54int getCharacteristic()
55{
56    return theCharacteristic;
57}
58
59int getGFDegree()
60{
61    //ASSERT( theDegree > 0, "not in GF(q)" );
62    return theDegree;
63}
64
65CanonicalForm getGFGenerator()
66{
67    ASSERT( theDegree > 1, "not in GF(q)" );
68    return int2imm_gf( 1 );
69}
Note: See TracBrowser for help on using the repository browser.