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

◆ power_mpz()

void M2::ARingRRi::power_mpz ( ElementType & result,
const ElementType & a,
mpz_srcptr n ) const
inline

Definition at line 300 of file aring-RRi.hpp.

301 {
302 if (mpz_cmp_si(n,2)>=0)
303 {
304 mpz_t r;
305 mpz_init(r);
306 mpz_fdiv_r_ui(r,n,2);
307
308 ElementType b;
309 init(b);
310
311 mpz_t m;
312 mpz_init(m);
313
314 if (mpz_cmp_si(r,0) == 0)
315 {
316 mpz_cdiv_q_ui(m,n,2);
317
318 power_mpz(b,a,m);
319 mult(result,b,b);
320 }
321 else
322 {
323 mpz_sub_ui(m,n,1);
324
325 power_mpz(b,a,m);
326 mult(result,a,b);
327 }
328 mpz_clear(r);
329 mpz_clear(m);
330 }
331 else if (mpz_cmp_si(n,1)==0)
332 mpfi_set(&result,&a);
333 else if (mpz_cmp_si(n,0)==0)
334 mpfi_set_si(&result,1);
335 else if (mpz_cmp_si(n,0)<0)
336 throw 20;
337 }
void init(ElementType &result) const
void mult(ElementType &result, const ElementType &a, const ElementType &b) const
void power_mpz(ElementType &result, const ElementType &a, mpz_srcptr n) const
VALGRIND_MAKE_MEM_DEFINED & result(result)

References init(), mult(), power_mpz(), and result().

Referenced by power_mpz(), and TEST().