Macaulay2 Engine
Loading...
Searching...
No Matches

◆ power() [2/2]

ring_elem GF::power ( const ring_elem f,
mpz_srcptr n ) const
virtual

Exponentiation. This is the default function, if a class doesn't define this.

Reimplemented from Ring.

Definition at line 397 of file GF.cpp.

398{
399 if (f.get_int() != _ZERO)
400 {
401 int exp = RingZZ::mod_ui(n, Q1_);
402 int m = (f.get_int() * exp) % Q1_; // WARNING TODO: possible overflow! Check!
403 if (m <= 0) m += Q1_;
404 return ring_elem(m);
405 }
406 else
407 {
408 if (mpz_sgn(n) == 0)
409 return ring_elem(_ONE);
410 else if (mpz_sgn(n) > 0)
411 return ring_elem(_ZERO);
412 else
413 throw exc::division_by_zero_error();
414 }
415}
int Q1_
Definition GF.hpp:71
int _ONE
Definition GF.hpp:73
int _ZERO
Definition GF.hpp:72
static unsigned int mod_ui(mpz_srcptr n, unsigned int p)
Definition ZZ.cpp:55
const mpreal exp(const mpreal &x, mp_rnd_t r=mpreal::get_default_rnd())
Definition mpreal.h:2298
int get_int() const
Definition ringelem.hpp:124

References _ONE, _ZERO, ring_elem::get_int(), RingZZ::mod_ui(), and Q1_.

Referenced by promote().