IntJacobi
Description
Compute the Jacobi symbol (a/n).
This public macro supports both forms:
IntJacobi(a, n)- returns the result, no error channel.IntJacobi(a, n, error)- writes the error flag througherror.
Parameters
| Name | Direction | Description |
|---|---|---|
a |
in | Numerator. |
n |
in | Odd positive modulus. |
error |
out | Optional pointer set to true on failure and false on success. |
Success
Returns -1, 0, or 1. Neither operand is modified.
Failure
Returns 0 when n is even, zero, or otherwise invalid for the Jacobi computation. With the two-argument form the caller cannot distinguish a true 0 result from failure; use the three-argument form with an error pointer to disambiguate.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Int.Math.c:632:
bool test_int_jacobi(void) {
WriteFmt("Testing IntJacobi\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Int.Math.c:641:
Int n = IntFrom(21, &alloc.base);
bool result = IntJacobi(&a, &p) == -1;
result = result && (IntJacobi(&b, &n) == 0);- In
Int.Math.c:642:
bool result = IntJacobi(&a, &p) == -1;
result = result && (IntJacobi(&b, &n) == 0);
IntDeinit(&a);- In
Int.Math.c:1071:
bool test_int_jacobi_even_denominator(void) {
WriteFmt("Testing IntJacobi even denominator handling\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Int.Math.c:1081:
bool result = !IntTryJacobi(&symbol, &a, &n);
result = result && (IntJacobi(&a, &n, &error) == 0);
result = result && (symbol == 99);
result = result && error;
Last updated on