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:2458:
{
bool prime_error = false;
bool prime = IntIsProbablePrime(modulus, &prime_error);
if (prime_error) {- In
Int.Math.c:872:
bool test_int_is_probable_prime(void) {
WriteFmt("Testing IntIsProbablePrime\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Int.Math.c:879:
Int composite = IntFrom(561, &alloc.base);
bool result = IntIsProbablePrime(&prime);
result = result && !IntIsProbablePrime(&composite);- In
Int.Math.c:880:
bool result = IntIsProbablePrime(&prime);
result = result && !IntIsProbablePrime(&composite);
IntDeinit(&prime);
Last updated on