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

◆ TEST() [6/7]

TEST ( ARingRRi ,
power_and_invert  )

Definition at line 271 of file ARingRRiTest.cpp.

272{
273 M2::ARingRRi R(100);
275 M2::ARingRRi::ElementType a, b, c, d;
276 R.init(a);
277 R.init(b);
278 R.init(c);
279 R.init(d);
280 mpz_t gmp1;
281 mpz_init(gmp1);
282
283 for (int i = 0; i < ntrials; i++)
284 {
285 gen.nextElement(a);
286 // TODO: what should the answer here be?
287 // EXPECT_TRUE(R->is_equal(R->power(a, 0), R->one())); // 0^0 == 1 too?
288 R.power(b, a, 1);
289 EXPECT_TRUE(R.is_equal(b, a));
290
291 int e1 = rawRandomInt(10) + 1;
292 int e2 = rawRandomInt(10) + 1;
293 R.power(b, a, e1);
294 R.power(c, a, e2);
295 R.power(d, a, e1 + e2);
296 R.mult(c, b, c);
297 EXPECT_TRUE(almostEqual(R,-94,c,d));
298
299 // Make sure that powers via mpz work (at least for small exponents)
300 mpz_set_si(gmp1, e1);
301 R.power_mpz(d, a, gmp1);
302 EXPECT_TRUE(R.is_equal(d, b));
303 }
304 mpz_clear(gmp1);
305 R.clear(d);
306 R.clear(c);
307 R.clear(b);
308 R.clear(a);
309}
bool almostEqual(const M2::ARingRRi &R, int nbits, const M2::ARingRRi::ElementType &a, const M2::ARingRRi::ElementType &b)
const int ntrials
Definition ARingTest.hpp:42
aring-style adapter for arbitrary-precision real intervals, backed by MPFI.
Definition aring-RRi.hpp:69
int32_t rawRandomInt(int32_t max)
Definition random.cpp:44

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