IntNextPrime
Description
Find the next probable prime greater than or equal to a value.
Parameters
| Name | Direction | Description |
|---|---|---|
result |
out | Destination for the prime |
value |
in | Starting point |
Usage example (from documentation)
bool ok = IntNextPrime(&prime, &value);Success
Returns true. *result holds the smallest probable prime >= *value.
Failure
Returns false on allocator OOM during the witness loop, or if the primality oracle gives up. *result is left untouched.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Int.c:3199:
}
bool IntNextPrime(Int *result, const Int *value) {
bool error = false;- In
Math.c:899:
bool test_int_next_prime(void) {
WriteFmt("Testing IntNextPrime\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:907:
Str text = StrInit(&alloc.base);
bool ok = IntNextPrime(&next, &value);
text = IntToStr(&next);- In
Math.c:3429:
///
bool test_m7_next_prime_of_zero_is_two(void) {
WriteFmt("Testing IntNextPrime(0) == 2\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:3436:
Int next = IntInit(&alloc.base);
bool ok = IntNextPrime(&next, &value);
bool result = ok && (IntToU64(&next) == 2);- In
Math.c:3457:
///
bool test_m7_next_prime_of_ten_is_eleven(void) {
WriteFmt("Testing IntNextPrime(10) == 11\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:3464:
Int next = IntInit(&alloc.base);
bool ok = IntNextPrime(&next, &value);
bool result = ok && (IntToU64(&next) == 11);- In
Math.c:3480:
///
bool test_m7_next_prime_of_nine_is_eleven(void) {
WriteFmt("Testing IntNextPrime(9) == 11\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:3487:
Int next = IntInit(&alloc.base);
bool ok = IntNextPrime(&next, &value);
bool result = ok && (IntToU64(&next) == 11);- In
Math.c:3504:
///
bool test_m7_next_prime_null_result(void) {
WriteFmt("Testing IntNextPrime(NULL result) aborts\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:3510:
Int value = IntFrom(10, &alloc.base);
(void)IntNextPrime(NULL, &value);
IntDeinit(&value);- In
Math.c:4617:
Int r = IntFrom(7u, a);
bool ok = IntNextPrime(&r, &v);
ok = ok && IntToU64(&r) == 1000003u;- In
Math.c:4638:
Int r1 = IntFrom(7u, a);
bool ok = IntNextPrime(&r0, &v0) && IntToU64(&r0) == 2u;
ok = ok && IntNextPrime(&r1, &v1) && IntToU64(&r1) == 3u;- In
Math.c:4639:
bool ok = IntNextPrime(&r0, &v0) && IntToU64(&r0) == 2u;
ok = ok && IntNextPrime(&r1, &v1) && IntToU64(&r1) == 3u;
IntDeinit(&v0);- In
Math.c:4828:
Int next = IntFrom(0u, alloc);
bool ok = IntNextPrime(&next, &value);
ok = ok && IntCompare(&next, 101u) == 0;
Last updated on