Skip to content

IntTryJacobi

Description

Compute the Jacobi symbol (a/n).

Parameters

Name Direction Description
out out Destination for the Jacobi symbol; one of -1, 0, or 1 on success.
a in Numerator
n in Odd positive modulus

Usage example (from documentation)

  int symbol = 0;
  bool ok = IntTryJacobi(&symbol, &a, &n);

Success

Returns true and writes the Jacobi symbol to *out. Neither operand is modified.

Failure

Returns false when n is even, zero, or otherwise invalid for the Jacobi computation. *out is left untouched.

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    bool IntTryJacobi(int *out, const Int *a, const Int *n) {
        ValidateInt(a);
        ValidateInt(n);
    int IntJacobiWithError(const Int *a, const Int *n, bool *error) {
        int  out = 0;
        bool ok  = IntTryJacobi(&out, a, n);
    
        if (error) {
        {
            int jacobi = 0;
            if (!IntTryJacobi(&jacobi, &a, modulus) || jacobi != 1) {
                IntDeinit(&a);
                return false;
                int jacobi = 0;
    
                if (!IntTryJacobi(&jacobi, &z, modulus)) {
                    IntDeinit(&q);
                    IntDeinit(&z);
        int jr = 0;
    
        bool ok = IntTryJacobi(&jr, &x, &n);
    
        // a case where gcd(a,n) != 1 -> the *out=0 branch (frees nn at 1998)
        Int n2  = IntFrom(9u, a); // odd, gcd(15,9)=3
        int jr2 = 0;
        ok      = ok && IntTryJacobi(&jr2, &x2, &n2) && jr2 == 0;
    
        IntDeinit(&x);
        int  symbol = 99;
        bool error  = false;
        bool result = !IntTryJacobi(&symbol, &a, &n);
    
        result = result && (IntJacobi(&a, &n, &error) == 0);
    
        int  symbol = 99;
        bool ok     = IntTryJacobi(&symbol, &a, &n);
        bool result = ok && (symbol == -1);
Last updated on