Skip to content
IntIsProbablePrime

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 through error.

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