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

◆ power()

void M2::ARingRRi::power ( ElementType & result,
const ElementType & a,
int n ) const
inline

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

273 {
274 if (n >= 2)
275 {
276 if (n%2 == 0)
277 {
278 ElementType b;
279 init(b);
280 power(b,a,n/2);
281 mult(result,b,b);
282 }
283 else
284 {
285 ElementType b;
286 init(b);
287 power(b,a,n-1);
288 mult(result,a,b);
289 }
290 }
291 else if (n == 1)
292 mpfi_set(&result,&a);
293 else if (n == 0)
294 mpfi_set_si(&result,1);
295 else if (n<0)
296 throw 20;
297 }
void init(ElementType &result) const
void power(ElementType &result, const ElementType &a, int n) const
void mult(ElementType &result, const ElementType &a, const ElementType &b) const
VALGRIND_MAKE_MEM_DEFINED & result(result)

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

Referenced by power(), and TEST().