IntIsProbablePrime
Description
Test whether the integer is probably prime using a Miller-Rabin style primality check.
This public macro supports both forms:
IntIsProbablePrime(value)- returns the result, no error channel.IntIsProbablePrime(value, error)- writes the error flag througherror.
Parameters
| Name | Direction | Description |
|---|---|---|
value |
in | Integer to test. |
error |
out | Optional pointer set to true on internal failure and false on success. |
Success
Returns true when the value is probably prime.
Failure
Returns false for composite values. With the two-argument form, *error is set to true on internal allocation failure during the witness loop and false otherwise.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Int.c:2790:
{
bool prime_error = false;
bool prime = IntIsProbablePrime(modulus, &prime_error);
if (prime_error) {- In
Math.c:882:
bool test_int_is_probable_prime(void) {
WriteFmt("Testing IntIsProbablePrime\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:889:
Int composite = IntFrom(561, &alloc.base);
bool result = IntIsProbablePrime(&prime);
result = result && !IntIsProbablePrime(&composite);- In
Math.c:890:
bool result = IntIsProbablePrime(&prime);
result = result && !IntIsProbablePrime(&composite);
IntDeinit(&prime);- In
Math.c:3000:
bool test_m4_one_not_prime(void) {
WriteFmt("Testing IntIsProbablePrime(1) == false\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:3006:
Int value = IntFrom(1, &alloc.base);
bool result = !IntIsProbablePrime(&value);
IntDeinit(&value);- In
Math.c:3014:
bool test_m4_two_is_prime(void) {
WriteFmt("Testing IntIsProbablePrime(2) == true\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:3020:
Int value = IntFrom(2, &alloc.base);
bool result = IntIsProbablePrime(&value);
IntDeinit(&value);- In
Math.c:3028:
bool test_m4_four_not_prime(void) {
WriteFmt("Testing IntIsProbablePrime(4) == false\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:3034:
Int value = IntFrom(4, &alloc.base);
bool result = !IntIsProbablePrime(&value);
IntDeinit(&value);- In
Math.c:3042:
bool test_m4_three_is_prime(void) {
WriteFmt("Testing IntIsProbablePrime(3) == true\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:3048:
Int value = IntFrom(3, &alloc.base);
bool result = IntIsProbablePrime(&value);
IntDeinit(&value);- In
Math.c:3056:
bool test_m4_prime_97(void) {
WriteFmt("Testing IntIsProbablePrime(97) == true (deep witness loop)\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:3062:
Int value = IntFrom(97, &alloc.base);
bool result = IntIsProbablePrime(&value);
IntDeinit(&value);- In
Math.c:3070:
bool test_m4_composite_561(void) {
WriteFmt("Testing IntIsProbablePrime(561) == false (Carmichael)\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:3076:
Int value = IntFrom(561, &alloc.base);
bool result = !IntIsProbablePrime(&value);
IntDeinit(&value);- In
Math.c:3084:
bool test_m4_composite_1763(void) {
WriteFmt("Testing IntIsProbablePrime(1763 = 41*43) == false (reaches MR)\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:3090:
Int value = IntFrom(1763, &alloc.base);
bool result = !IntIsProbablePrime(&value);
IntDeinit(&value);- In
Math.c:3098:
bool test_m4_spsp_1373653_composite(void) {
WriteFmt("Testing IntIsProbablePrime(1373653) == false (SPSP base 2,3)\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:3104:
Int value = IntFromStr("1373653", &alloc.base);
bool result = !IntIsProbablePrime(&value);
IntDeinit(&value);- In
Math.c:3112:
bool test_m4_large_prime(void) {
WriteFmt("Testing IntIsProbablePrime(1000000007) == true\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:3118:
Int value = IntFromStr("1000000007", &alloc.base);
bool result = IntIsProbablePrime(&value);
IntDeinit(&value);- In
Math.c:3126:
bool test_m4_error_flag_cleared(void) {
WriteFmt("Testing IntIsProbablePrime clears the error flag\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:3133:
bool error = true;
bool prime = IntIsProbablePrime(&value, &error);
bool result = prime && !error;- In
Math.c:4582:
Int composite = IntFrom(1000005u, a); // composite
bool ok = IntIsProbablePrime(&prime) && !IntIsProbablePrime(&composite);
IntDeinit(&prime);- In
Math.c:4600:
Int n = IntFrom(2047u, a);
bool ok = !IntIsProbablePrime(&n);
IntDeinit(&n);- In
Math.c:4845:
Int value = IntFrom(561u, alloc);
bool error = false;
bool prime = IntIsProbablePrime(&value, &error);
bool ok = (error == false) && (prime == false);
Last updated on