Givaro
examples/FiniteField/all_field.C

NO DOC

// Copyright(c)'1994-2009 by The Givaro group
// This file is part of Givaro.
// Givaro is governed by the CeCILL-B license under French law
// and abiding by the rules of distribution of free software.
// see the COPYRIGHT file for more details.
#include <iostream>
#include <givaro/gfq.h>
#include <givaro/montgomery.h>
#include <givaro/modular.h>
#include <givaro/StaticElement.h>
using namespace Givaro;
namespace Givaro {
// Domain kind
#ifdef GIVARO_USE_SIXTYFOUR
template<>
Field8 Element8::_domain(2);
#endif
}
template<class Field, class Element>
void TestField()
{
uint64_t P = 251;
// Initialization of static member
// Initialisations of elements
Element a(2),b(-29.8),c(33),d(Integer("123456789012345678901234567890")),e(0);
e += (a = b); std::cout << a << " = " << b << " mod " << P << ";" << std::endl;
e += (a = b + c); std::cout << a << " = " << b << " + " << c << " mod " << P << ";" << std::endl;
e += (a = b - c); std::cout << a << " = " << b << " - " << c << " mod " << P << ";" << std::endl;
e += (a = b * c); std::cout << a << " = " << b << " * " << c << " mod " << P << ";" << std::endl;
e += (a = b / c); std::cout << a << " = " << b << " / " << c << " mod " << P << ";" << std::endl;
std::cout << d << " + " << a << " mod " << P << " = "; e += (d += a); std::cout << d << ";" << std::endl;
std::cout << d << " - " << a << " mod " << P << " = "; e += (d -= a); std::cout << d << ";" << std::endl;
std::cout << d << " * " << a << " mod " << P << " = "; e += (d *= a); std::cout << d << ";" << std::endl;
std::cout << d << " / " << a << " mod " << P << " = "; e += (d /= a); std::cout << d << ";" << std::endl;
std::cout << a << " is non zero ? " << (a != Element(0) ) << std::endl;
a = 0; std::cout << a << " is zero ? " << (a == Element(0) ) << std::endl;
double dd(0.0); dd += (double)(e); dd += (float)e; dd += (uint32_t)e;
Element::getDomain().write( std::cerr << "Test: " << dd << " within ") << std::endl;
}
int main(int argc, char ** argv) {
TestField<Field1, Element1>();
TestField<Field2, Element2>();
TestField<Field3, Element3>();
TestField<Field4, Element4>();
TestField<Field5, Element5>();
TestField<Field6, Element6>();
TestField<Field7, Element7>();
#ifdef GIVARO_USE_SIXTYFOUR
TestField<Field8, Element8>();
#endif
return 0;
}