FLINT3.7.0-dev
Module · 8 functions

long_extras.h

#include <flint/long_extras.h>

This module collects a few functions on signed words (slong) that complement the unsigned word functions of ulong_extras.h. The prefix z_ stands for a signed integer, as in the GMP conventions.

Properties#

size_t z_sizeinbase(slong n, int b)

Returns the number of digits of |n| in base b \ge 2, the sign not counted. For n = 0 it returns 1. Unlike GMP's mpz_sizeinbase, the result is exact for every base.

Checked arithmetic#

Set *a to b + c or b c and return 0 if the result fits in an slong; otherwise return 1, and *a holds the exact result reduced modulo 2^{\mathtt{FLINT\_BITS}} (into the range of slong). With GCC and Clang they compile to the overflow-checking built-ins.

Returns 1 if the determinant m_{11} m_{22} - m_{12} m_{21} is negative and 0 otherwise. The determinant is computed exactly in two words, so there is no overflow for any inputs.

Random functions#

Returns a random value for testing. With probability 1/8 it is one of the special values 0, 1, -1, COEFF_MAX, COEFF_MIN, WORD_MAX and WORD_MIN, chosen uniformly; otherwise it is a nonnegative random value of between 0 and \mathtt{FLINT\_BITS} - 1 bits, produced by n_randbits.

As z_randtest, but never returns 0.

Returns a random value z with |z| < limit and a random sign (so 0 is returned twice as often as other values). If limit is zero or larger than WORD_MAX, it is replaced by WORD_MAX. The absolute value is n_randlimb(state) % limit, which is close to uniform.

Number theory#

Returns the Kronecker symbol \left(\frac{a}{n}\right) for any a and n, including negative and even n and n = 0 (where the symbol is 1 if a = \pm 1 and 0 otherwise). For odd positive n this is the Jacobi symbol, which n_jacobi also computes.

Cite this page

The FLINT team, “long_extras.h (module overview),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/long_extras/index.html (generated 2026-10-20).