Skip to content
IntIsProbablePrime

IntIsProbablePrime

IntIsProbablePrime

Description

Perform a probabilistic primality test.

This is a probable-prime test, not a proof of primality.

Parameters

Name Direction Description
value in Integer to test

Usage example (from documentation)

  bool prime = IntIsProbablePrime(&value);

Returns

true when the value is probably prime.

Usage example (Cross-references)

Usage examples (Cross-references)
            return true;
        }
        if (IntIsEven(modulus) || !IntIsProbablePrime(modulus)) {
            IntDeinit(&a);
            return false;
    }
    
    bool IntIsProbablePrime(Int *value) {
        static const u64 bases[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37};
        }
    
        while (!IntIsProbablePrime(&candidate)) {
            MISRA_PRIV_IntAddU64(&candidate, &candidate, 2);
        }
    
    bool test_int_is_probable_prime(void) {
        WriteFmt("Testing IntIsProbablePrime\n");
    
        Int prime = IntFromStr("1000000007");
        Int composite = IntFrom(561);
    
        bool result = IntIsProbablePrime(&prime);
        result      = result && !IntIsProbablePrime(&composite);
    
        bool result = IntIsProbablePrime(&prime);
        result      = result && !IntIsProbablePrime(&composite);
    
        IntDeinit(&prime);
Last updated on