d_vec.h
#include <flint/d_vec.h>This module provides basic operations on vectors of double, given as a pointer and a length. All arithmetic uses the default rounding of the processor (round to nearest). Besides plain loops it offers two dot products that return an error estimate: a cheap heuristic one and the compensated "dot product in thrice the working precision" of Ogita, Rump and Oishi [ORO2005], whose result is as accurate as if computed with about 159-bit arithmetic and then rounded. For vectors of double-word or quad-double numbers, see the _dN_vec_ functions of dfloat.
Unless stated otherwise, output vectors may alias input vectors.
Memory management#
double * _d_vec_init(slong len)Returns a newly allocated vector of len doubles. The entries are not initialised.
void _d_vec_clear(double * vec)Frees a vector allocated by _d_vec_init.
Random generation#
void _d_vec_randtest(double * f, flint_rand_t state, slong len, slong minexp, slong maxexp)Sets the len entries of f to random values from d_randtest_signed: signed numbers with exponents between minexp and maxexp, or zero.
Assignment#
void _d_vec_set(double * vec1, const double * vec2, slong len2)Copies the len2 entries of vec2 to vec1.
void _d_vec_zero(double * vec, slong len)Sets the len entries of vec to zero.
Comparison#
int _d_vec_equal(const double * vec1, const double * vec2, slong len)Returns 1 if the entries of the two vectors are equal as doubles (so that +0 = -0, and a NaN entry makes the result 0 unless the pointers coincide), and 0 otherwise.
int _d_vec_approx_equal(const double * vec1, const double * vec2, slong len, double eps)Returns 1 if |\mathit{vec1}[i] - \mathit{vec2}[i]| \le \varepsilon for every i (an absolute tolerance, with the difference rounded to nearest), and 0 otherwise.
int _d_vec_is_zero(const double * vec, slong len)Returns 1 if every entry is zero, and 0 otherwise.
int _d_vec_is_approx_zero(const double * vec, slong len, double eps)Returns 1 if |\mathit{vec}[i]| \le \varepsilon for every i, and 0 otherwise.
Arithmetic#
void _d_vec_add(double * res, const double * vec1, const double * vec2, slong len2)void _d_vec_sub(double * res, const double * vec1, const double * vec2, slong len2)Set res to the entrywise sum or difference of the two vectors of length len2.
void _d_vec_mul_2exp(double * res, const double * x, slong len, int e)Sets res to the vector x multiplied by 2^e, which is exact unless an entry overflows or becomes subnormal (see d_mul_2exp).
Dot products and norms#
double _d_vec_dot(const double * vec1, const double * vec2, slong len2)Returns the dot product of the two vectors, accumulated from left to right in double precision. The error is bounded by \gamma_{n} \sum_i |x_i y_i| with \gamma_n = n u/(1 - n u), u = 2^{-53} and n the length, barring overflow and underflow [MBD2018].
double _d_vec_norm(const double * vec, slong len)Returns the square \sum_i x_i^2 of the Euclidean norm (not the norm itself), accumulated in double precision.
double _d_vec_dot_heuristic(const double * vec1, const double * vec2, slong len2, double * err)Returns the dot product computed by summing the nonnegative and the negative products separately and subtracting the two sums at the end. If err is not NULL, sets *err to 2 n \max(2^{e_p - 53}, 2^{e_q - 53}), where 2^{e_p} and 2^{e_q} bound the two partial sums and n is the length. This is an estimate of the error, not a rigorous bound: it does not account for overflow or underflow, and the factor 2n is heuristic for long vectors.
double _d_vec_dot_thrice(const double * vec1, const double * vec2, slong len2, double * err)Returns the dot product computed as if in three times the working precision and then rounded to double, using error-free transformations (the algorithm Dot3 of Ogita, Rump and Oishi [ORO2005]). The result is accurate to nearly full double precision unless the dot product is extremely ill-conditioned. If err is not NULL, sets *err to the error bound of [ORO2005] in terms of the returned value r, evaluated in double precision: (\varepsilon + 2\gamma^2) |r| + \gamma^3 \|x\|_2 \|y\|_2 with \varepsilon = 2^{-52} and \gamma = (4n-2)\varepsilon / (1 - (4n-2)\varepsilon).
References#
- [ORO2005] T. Ogita, S. M. Rump and S. Oishi. Accurate sum and dot product. SIAM Journal on Scientific Computing 26:6 (2005), 1955–1988. https://doi.org/10.1137/030601818
- [MBD2018] J.-M. Muller, N. Brunie, F. de Dinechin, C.-P. Jeannerod, M. Joldes, V. Lefèvre, G. Melquiond, N. Revol and S. Torres, Handbook of Floating-Point Arithmetic, second edition, Birkhäuser (2018), https://doi.org/10.1007/978-3-319-76526-6
The FLINT team, “d_vec.h (module overview),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/d_vec/index.html (generated 2026-10-20).
@misc{flint-doc-d-vec-index,
author = {{The FLINT team}},
title = {{d\_vec.h (module overview)}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/d_vec/index.html},
note = {Generated 2026-10-20}
}