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

◆ TEST() [6/7]

TEST ( ARingRRR ,
power_and_invert  )

Definition at line 253 of file ARingRRRTest.cpp.

254{
255 M2::ARingRRR R(100);
257 M2::ARingRRR::ElementType a, b, c, d;
258 R.init(a);
259 R.init(b);
260 R.init(c);
261 R.init(d);
262 mpz_t gmp1;
263 mpz_init(gmp1);
264 for (int i = 0; i < ntrials; i++)
265 {
266 gen.nextElement(a);
267 // TODO: what should the answer here be?
268 // EXPECT_TRUE(R->is_equal(R->power(a, 0), R->one())); // 0^0 == 1 too?
269 R.power(b, a, 1);
270 EXPECT_TRUE(R.is_equal(b, a));
271
272 int e1 = rawRandomInt(10) + 1;
273 int e2 = rawRandomInt(10) + 1;
274 R.power(b, a, e1);
275 R.power(c, a, e2);
276 R.power(d, a, e1 + e2);
277 R.mult(c, b, c);
278 EXPECT_TRUE(almostEqual(R, 96, c, d));
279
280 // Make sure that powers via mpz work (at least for small exponents)
281 mpz_set_si(gmp1, e1);
282 R.power_mpz(d, a, gmp1);
283 EXPECT_TRUE(R.is_equal(d, b));
284 }
285 mpz_clear(gmp1);
286 R.clear(d);
287 R.clear(c);
288 R.clear(b);
289 R.clear(a);
290}
bool almostEqual(const M2::ARingRRR &R, int nbits, const M2::ARingRRR::ElementType &a, const M2::ARingRRR::ElementType &b)
const int ntrials
Definition ARingTest.hpp:42
aring-style adapter for arbitrary-precision real numbers, backed by MPFR.
Definition aring-RRR.hpp:70
int32_t rawRandomInt(int32_t max)
Definition random.cpp:44

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