398{
399
400
401
402
403
404
405
406
407
408
409
411 typename T::ElementType a, b, c, d, one;
412 int q = static_cast<int>(R.cardinality());
413 R.init(one);
414 R.init(a);
415 R.init(b);
416 R.init(c);
417 R.init(d);
418 R.set_from_long(one, 1);
419 for (
int i = 0; i <
ntrials; i++)
420 {
421 gen.nextElement(a);
422 gen.nextElement(b);
423
424 R.power(c, a, q);
425 EXPECT_TRUE(R.is_equal(c, a));
426
427 if (R.is_zero(a)) continue;
428
429 R.power(c, a, q - 1);
430 EXPECT_TRUE(R.is_equal(c, one));
431
432 R.power(c, a, -1);
433 R.mult(c, a, c);
434 EXPECT_TRUE(R.is_equal(c, one));
435
436 R.power(c, a, -2);
437 R.power(d, a, 3);
438 R.mult(d, c, d);
439 EXPECT_TRUE(R.is_equal(d, a));
440 }
441 R.clear(a);
442 R.clear(b);
443 R.clear(c);
444 R.clear(d);
445 R.clear(one);
446}