Skip to content
IntJacobiWithError

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)
    
        static inline int int_jacobi_no_error(const Int *a, const Int *n) {
            return IntJacobiWithError(a, n, NULL);
        }
    /// TAGS: Int, Math, Jacobi, NumberTheory, Macro
    ///
    #define IntJacobi(...) INT_JACOBI_SELECT(__VA_ARGS__, IntJacobiWithError, int_jacobi_no_error)(__VA_ARGS__)
    
    #ifdef __cplusplus
    }
    
    int IntJacobiWithError(const Int *a, const Int *n, bool *error) {
        int  out = 0;
        bool ok  = IntTryJacobi(&out, a, n);
    ///
    bool test_m29_jacobi_error_flag_success_and_failure(void) {
        WriteFmt("Testing IntJacobiWithError error flag both directions\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        bool err_bad = false;
    
        int sym = IntJacobiWithError(&a, &n_odd, &err_ok);
        (void)IntJacobiWithError(&a, &n_even, &err_bad);
    
        int sym = IntJacobiWithError(&a, &n_odd, &err_ok);
        (void)IntJacobiWithError(&a, &n_even, &err_bad);
    
        bool result = (sym == 1);
Last updated on