source: git/factory/cf_char.cc @ 8f5493

spielwiese
Last change on this file since 8f5493 was d1427e8, checked in by Hans Schoenemann <hannes@…>, 4 years ago
factory: support FLINT 2.5.2
  • Property mode set to 100644
File size: 1.8 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#include "int_pp.h"
20
21#ifdef HAVE_FLINT
22#include "FLINTconvert.h" // for __FLINT_RELEASE
23#endif
24
25STATIC_VAR int theCharacteristic = 0;
26STATIC_VAR int theDegree = 1;
27
28void setCharacteristic( int c )
29{
30    if ( c == 0 )
31    {
32        theDegree = 0;
33        CFFactory::settype( IntegerDomain );
34        theCharacteristic = 0;
35    }
36    else
37    {
38        theDegree = 1;
39        CFFactory::settype( FiniteFieldDomain );
40        ff_big = c > cf_getSmallPrime( cf_getNumSmallPrimes()-1 );
41        if (c!=theCharacteristic)
42        {
43          if (c > 536870909) factoryError("characteristic is too large(max is 2^29)");
44          ff_setprime( c );
45        }
46        theCharacteristic = c;
47    }
48}
49
50#if !defined(HAVE_NTL)
51#if !defined(HAVE_FLINT) || (__FLINT_RELEASE<=20600)
52void setCharacteristic( int c, int n )
53{
54    ASSERT( c > 1 && n > 0, "illegal characteristic" );
55    setCharacteristic( c );
56    InternalPrimePower::setPrimePower( c, n );
57    CFFactory::settype( PrimePowerDomain );
58}
59#endif
60#endif
61
62
63void setCharacteristic( int c, int n, char name )
64{
65    ASSERT( c != 0 && n > 1, "illegal GF(q)" );
66    setCharacteristic( c );
67    gf_setcharacteristic( c, n, name );
68    theDegree = n;
69    CFFactory::settype( GaloisFieldDomain );
70}
71
72int getCharacteristic()
73{
74    return theCharacteristic;
75}
76
77int getGFDegree()
78{
79    //ASSERT( theDegree > 0, "not in GF(q)" );
80    return theDegree;
81}
82
83CanonicalForm getGFGenerator()
84{
85    ASSERT( theDegree > 1, "not in GF(q)" );
86    return int2imm_gf( 1 );
87}
Note: See TracBrowser for help on using the repository browser.