Skip to content

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 through error.

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)
    
    bool test_int_jacobi(void) {
        WriteFmt("Testing IntJacobi\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Int n = IntFrom(21, &alloc.base);
    
        bool result = IntJacobi(&a, &p) == -1;
        result      = result && (IntJacobi(&b, &n) == 0);
    
        bool result = IntJacobi(&a, &p) == -1;
        result      = result && (IntJacobi(&b, &n) == 0);
    
        IntDeinit(&a);
    
    bool test_int_jacobi_even_denominator(void) {
        WriteFmt("Testing IntJacobi even denominator handling\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        bool result = !IntTryJacobi(&symbol, &a, &n);
    
        result = result && (IntJacobi(&a, &n, &error) == 0);
        result = result && (symbol == 99);
        result = result && error;
Last updated on