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

◆ TEST() [6/7]

TEST ( ARingCC ,
power_and_invert  )

Definition at line 244 of file ARingCCTest.cpp.

245{
246 M2::ARingCC C;
247 auto nbits = C.get_precision();
249 M2::ARingCC::ElementType a, b, c, d;
250 C.init(a);
251 C.init(b);
252 C.init(c);
253 C.init(d);
254 mpz_t gmp1;
255 mpz_init(gmp1);
256 for (int i = 0; i < ntrials; i++)
257 {
258 gen.nextElement(a);
259 // TODO: what should the answer here be?
260 // EXPECT_TRUE(R->is_equal(R->power(a, 0), R->one())); // 0^0 == 1 too?
261 C.power(b, a, 1);
262 EXPECT_TRUE(C.is_equal(b, a));
263
264 int e1 = rawRandomInt(10) + 1;
265 int e2 = rawRandomInt(10) + 1;
266 C.power(b, a, e1);
267 C.power(c, a, e2);
268 C.power(d, a, e1 + e2);
269 C.mult(c, b, c);
270 EXPECT_TRUE(almostEqual(C, nbits - 11, c, d)); /* exponentiation gives
271 relatively small number
272 of correct digits */
273
274 // Make sure that powers via mpz work (at least for small exponents)
275 mpz_set_si(gmp1, e1);
276 C.power_mpz(d, a, gmp1);
277 EXPECT_TRUE(fabs(d.re - b.re) < 1.e-14);
278 EXPECT_TRUE(fabs(d.im - b.im) < 1.e-14);
279 }
280 mpz_clear(gmp1);
281 C.clear(d);
282 C.clear(c);
283 C.clear(b);
284 C.clear(a);
285}
bool almostEqual(const M2::ARingCC &C, unsigned long nbits, const M2::ARingCC::ElementType &a, const M2::ARingCC::ElementType &b)
const int ntrials
Definition ARingTest.hpp:42
void power(ElementType &result, const ElementType &a, int n) const
Definition aring-CC.hpp:361
void power_mpz(ElementType &result, const ElementType &a, mpz_srcptr n) const
Definition aring-CC.hpp:390
void mult(ElementType &res, const ElementType &a, const RealElementType &b) const
Definition aring-CC.hpp:303
elem ElementType
Definition aring-CC.hpp:81
bool is_equal(const ElementType &f, const ElementType &g) const
Definition aring-CC.hpp:108
void init(ElementType &result) const
Definition aring-CC.hpp:150
unsigned long get_precision() const
Definition aring-CC.hpp:88
static void clear(ElementType &result)
Definition aring-CC.hpp:164
aring-style adapter for double-precision complex numbers, stored as (double, double) pairs.
Definition aring-CC.hpp:72
const mpreal fabs(const mpreal &x, mp_rnd_t r=mpreal::get_default_rnd())
Definition mpreal.h:2293
int32_t rawRandomInt(int32_t max)
Definition random.cpp:44

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