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

◆ TEST() [7/9]

TEST ( RingCCC ,
power  )

Definition at line 171 of file RingCCCTest.cpp.

172{
173 RingCCC *R = RingCCC::create(100);
174
175 mpz_t gmp1;
176 mpz_init(gmp1);
178 for (int i = 0; i < ntrials; i++)
179 {
180 ring_elem a = gen.nextElement();
181 // TODO: what should the answer here be?
182 // EXPECT_TRUE(R->is_equal(R->power(a, 0), R->one())); // 0^0 == 1 too?
183 EXPECT_TRUE(R->is_equal(R->power(a, 1), a));
184
185 int e1 = rawRandomInt(10) + 1;
186 int e2 = rawRandomInt(10) + 1;
187 // std::cout << "(" << e1 << "," << e2 << ")" << std::endl;
188 ring_elem b = R->power(a, e1);
189 ring_elem c = R->power(a, e2);
190 ring_elem d = R->power(a, e1 + e2);
191#if 0
192 ring_elem e = R->mult(b,c);
193 mpfr_printf("b=(%.30Rf,%.30Rf)\n",BIGCC_RE(b), BIGCC_IM(b));
194 mpfr_printf("c=(%.30Rf,%.30Rf)\n",BIGCC_RE(c), BIGCC_IM(c));
195 mpfr_printf("d=(%.30Rf,%.30Rf)\n",BIGCC_RE(d), BIGCC_IM(d));
196 mpfr_printf("e=(%.30Rf,%.30Rf)\n",BIGCC_RE(e), BIGCC_IM(e));
197#endif
198 EXPECT_TRUE(almostEqual(R, 80, R->mult(b, c), d));
199
200 // Make sure that powers via mpz work (at least for small exponents)
201 mpz_set_si(gmp1, e1);
202 ring_elem b1 = R->power(a, gmp1);
203 EXPECT_TRUE(R->is_equal(b1, b));
204 }
205 mpz_clear(gmp1);
206}
const int ntrials
Definition ARingTest.hpp:42
M2::ConcreteRing< M2::ARingCCC > RingCCC
bool almostEqual(const RingCCC *R, int nbits, ring_elem a, ring_elem b)
virtual ring_elem mult(const ring_elem f, const ring_elem g) const
static ConcreteRing< M2::ARingCCC > * create(std::unique_ptr< M2::ARingCCC > R)
virtual ring_elem power(const ring_elem f, mpz_srcptr n) const
Exponentiation. This is the default function, if a class doesn't define this.
virtual bool is_equal(const ring_elem f, const ring_elem g) const
int32_t rawRandomInt(int32_t max)
Definition random.cpp:44
#define BIGCC_RE(f)
Definition ringelem.hpp:210
#define BIGCC_IM(f)
Definition ringelem.hpp:209

References almostEqual(), BIGCC_IM, BIGCC_RE, M2::ConcreteRing< M2::ARingCCC >::create(), M2::ConcreteRing< RingType >::is_equal(), M2::ConcreteRing< RingType >::mult(), RingElementGenerator< RingType >::nextElement(), ntrials, M2::ConcreteRing< RingType >::power(), and rawRandomInt().