gmp_libmpz_powm Method |
Namespace: Math.Gmp.Native
Negative exp is supported if an inverse base^-1 modulo mod exists (see mpz_invert). If an inverse doesn’t exist then a divide by zero is raised.
// Create, initialize, and set the value of base to 2. mpz_t @base = new mpz_t(); gmp_lib.mpz_init_set_ui(@base, 2U); // Create, initialize, and set the value of exp to 4. mpz_t exp = new mpz_t(); gmp_lib.mpz_init_set_ui(exp, 4U); // Create, initialize, and set the value of mod to 3. mpz_t mod = new mpz_t(); gmp_lib.mpz_init_set_ui(mod, 3U); // Create, initialize, and set the value of rop to 0. mpz_t rop = new mpz_t(); gmp_lib.mpz_init(rop); // Set rop = base^exp mod mod. gmp_lib.mpz_powm(rop, @base, exp, mod); // Assert that rop is 1. Assert.IsTrue(gmp_lib.mpz_get_si(rop) == 1); // Release unmanaged memory allocated for rop, base, exp, and mod. gmp_lib.mpz_clears(rop, @base, exp, mod, null);