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

◆ TEST() [6/7]

TEST ( ARingRR ,
power_and_invert  )

Definition at line 259 of file ARingRRTest.cpp.

260{
261 M2::ARingRR R;
262 auto nbits = R.get_precision();
264 M2::ARingRR::ElementType a, b, c, d;
265 R.init(a);
266 R.init(b);
267 R.init(c);
268 R.init(d);
269 mpz_t gmp1;
270 mpz_init(gmp1);
271 for (int i = 0; i < ntrials; i++)
272 {
273 gen.nextElement(a);
274 // TODO: what should the answer here be?
275 // EXPECT_TRUE(R->is_equal(R->power(a, 0), R->one())); // 0^0 == 1 too?
276 R.power(b, a, 1);
277 EXPECT_TRUE(R.is_equal(b, a));
278
279 int e1 = rawRandomInt(10) + 1;
280 int e2 = rawRandomInt(10) + 1;
281 R.power(b, a, e1);
282 R.power(c, a, e2);
283 R.power(d, a, e1 + e2);
284 R.mult(c, b, c);
285 EXPECT_TRUE(almostEqual(R, nbits - 4, c, d));
286
287 // Make sure that powers via mpz work (at least for small exponents)
288 mpz_set_si(gmp1, e1);
289 R.power_mpz(d, a, gmp1);
290 EXPECT_TRUE(R.is_equal(d, b));
291 }
292 mpz_clear(gmp1);
293 R.clear(d);
294 R.clear(c);
295 R.clear(b);
296 R.clear(a);
297}
bool almostEqual(const M2::ARingRR &R, unsigned long nbits, const M2::ARingRR::ElementType &a, const M2::ARingRR::ElementType &b)
const int ntrials
Definition ARingTest.hpp:42
void init(ElementType &result) const
Definition aring-RR.hpp:124
void mult(ElementType &result, const ElementType &a, const ElementType &b) const
Definition aring-RR.hpp:203
elem ElementType
Definition aring-RR.hpp:68
static void clear(ElementType &result)
Definition aring-RR.hpp:128
unsigned long get_precision() const
Definition aring-RR.hpp:73
void power(ElementType &result, const ElementType &a, int n) const
Definition aring-RR.hpp:227
void power_mpz(ElementType &result, const ElementType &a, mpz_srcptr n) const
Definition aring-RR.hpp:232
bool is_equal(const ElementType &f, const ElementType &g) const
Definition aring-RR.hpp:87
aring-style adapter for double-precision real numbers.
Definition aring-RR.hpp:62
int32_t rawRandomInt(int32_t max)
Definition random.cpp:44

References almostEqual(), M2::ARingRR::clear(), M2::ARingRR::get_precision(), M2::ARingRR::init(), M2::ARingRR::is_equal(), M2::ARingRR::mult(), ARingElementGenerator< RingType >::nextElement(), ntrials, M2::ARingRR::power(), M2::ARingRR::power_mpz(), and rawRandomInt().