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

◆ power() [2/2]

ring_elem Z_mod::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 264 of file ZZp.cpp.

265{
266 if (f.get_int() == _ZERO) {
267 if (mpz_sgn(n)<0) throw exc::division_by_zero_error();
268 else if (mpz_sgn(n) == 0)
269 return ring_elem(0);
270 return ring_elem(_ZERO);
271 }
272 int n1 = RingZZ::mod_ui(n, _P1);
273 int m = (f.get_int() * n1) % _P1;
274 if (m < 0) m += _P1;
275 return ring_elem(m);
276}
static unsigned int mod_ui(mpz_srcptr n, unsigned int p)
Definition ZZ.cpp:55
int _ZERO
Definition ZZp.hpp:68
int _P1
Definition ZZp.hpp:67
int get_int() const
Definition ringelem.hpp:124

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