IntJacobiWithError
Description
Compute the Jacobi symbol (a/n) with explicit failure channel.
Parameters
| Name | Direction | Description |
|---|---|---|
a |
in | Numerator. |
n |
in | Odd positive modulus. |
error |
out | Optional pointer set to true on failure (invalid n) and false on success. |
Success
Returns -1, 0, or 1 reflecting the Jacobi symbol. Neither operand is modified. When error is non-NULL, *error is set to false.
Failure
Returns 0 when n is even, zero, or otherwise invalid for the Jacobi computation. When error is non-NULL, *error is set to true so the caller can distinguish failure from a true 0 result.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Math.h:876:
static inline int int_jacobi_no_error(const Int *a, const Int *n) {
return IntJacobiWithError(a, n, NULL);
}- In
Math.h:901:
/// TAGS: Int, Math, Jacobi, NumberTheory, Macro
///
#define IntJacobi(...) INT_JACOBI_SELECT(__VA_ARGS__, IntJacobiWithError, int_jacobi_no_error)(__VA_ARGS__)
#ifdef __cplusplus- In
Int.c:2008:
}
int IntJacobiWithError(const Int *a, const Int *n, bool *error) {
int out = 0;
bool ok = IntTryJacobi(&out, a, n);- In
Int.Math.c:2662:
///
bool test_m29_jacobi_error_flag_success_and_failure(void) {
WriteFmt("Testing IntJacobiWithError error flag both directions\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Int.Math.c:2673:
bool err_bad = false;
int sym = IntJacobiWithError(&a, &n_odd, &err_ok);
(void)IntJacobiWithError(&a, &n_even, &err_bad);- In
Int.Math.c:2674:
int sym = IntJacobiWithError(&a, &n_odd, &err_ok);
(void)IntJacobiWithError(&a, &n_even, &err_bad);
bool result = (sym == 1);
Last updated on