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

◆ TEST() [6/7]

TEST ( ARingCCC ,
power_and_invert  )

Definition at line 248 of file ARingCCCTest.cpp.

249{
250 M2::ARingCCC C(100);
252 M2::ARingCCC::ElementType a, b, c, d;
253 C.init(a);
254 C.init(b);
255 C.init(c);
256 C.init(d);
257 mpz_t gmp1;
258 mpz_init(gmp1);
259 for (int i = 0; i < ntrials; i++)
260 {
261 gen.nextElement(a);
262 // TODO: what should the answer here be?
263 // EXPECT_TRUE(R->is_equal(R->power(a, 0), R->one())); // 0^0 == 1 too?
264 C.power(b, a, 1);
265 EXPECT_TRUE(C.is_equal(b, a));
266
267 int e1 = rawRandomInt(10) + 1;
268 int e2 = rawRandomInt(10) + 1;
269 C.power(b, a, e1);
270 C.power(c, a, e2);
271 C.power(d, a, e1 + e2);
272 C.mult(c, b, c);
273 EXPECT_TRUE(almostEqual(C, 90, c, d)); /* exponentiation gives
274 relatively small number
275 of correct digits */
276
277 // Make sure that powers via mpz work (at least for small exponents)
278 mpz_set_si(gmp1, e1);
279 C.power_mpz(d, a, gmp1);
280 EXPECT_TRUE(C.is_equal(d, b));
281 }
282 mpz_clear(gmp1);
283 C.clear(d);
284 C.clear(c);
285 C.clear(b);
286 C.clear(a);
287}
bool almostEqual(const M2::ARingCCC &C, int nbits, const M2::ARingCCC::ElementType &a, const M2::ARingCCC::ElementType &b)
const int ntrials
Definition ARingTest.hpp:42
aring-style adapter for arbitrary-precision complex numbers, stored as (MPFR, MPFR) pairs.
Definition aring-CCC.hpp:71
int32_t rawRandomInt(int32_t max)
Definition random.cpp:44

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