Skip to content

float64 #

Error-free transformations and double-double accumulators.

Plain f64 accumulation discards low-order bits at every step. The routines in this file keep the discarded part in a second f64 (a "double-double" value hi+lo with roughly 106 bits of precision), so sums and dot products stay accurate on inputs where naive left-to-right evaluation cancels catastrophically. They are the building blocks for correctly rounded elementary functions (see vlang/vsl#65).

fn acos #

fn acos(x f64) f64

acos returns acos(x) rounded from the double-double evaluation.

fn acos_dd #

fn acos_dd(x f64) (f64, f64)

acos_dd returns acos(x) as a double-double pair (hi, lo), computed as pi/2 - asin(x). For |x| > 1 it returns NaN, like math.acos.

fn alike #

fn alike(a f64, b f64) bool

alike exposes this operation as part of the public API.

fn all_nan #

fn all_nan(x []f64) bool

all_nan returns true if x contains only nan values, and false otherwise.

fn arrays_tolerance #

fn arrays_tolerance(data1 []f64, data2 []f64, tol f64) bool

arrays_tolerance exposes this operation as part of the public API.

fn asin #

fn asin(x f64) f64

asin returns asin(x) rounded from the double-double evaluation.

fn asin_dd #

fn asin_dd(x f64) (f64, f64)

asin_dd returns asin(x) as a double-double pair (hi, lo), computed as atan(x / sqrt(1 - x^2)). For |x| > 1 it returns NaN, like math.asin.

fn atan #

fn atan(x f64) f64

atan returns atan(x) rounded from the double-double evaluation.

fn atan_dd #

fn atan_dd(x f64) (f64, f64)

atan_dd returns atan(x) as a double-double pair (hi, lo).

fn axpy_inc #

fn axpy_inc(alpha f64, x []f64, mut y []f64, n u32, incX u32, incY u32, ix u32, iy u32)

axpy_inc

fn axpy_inc_to #

fn axpy_inc_to(mut dst []f64, incdst u32, idst u32, alpha f64, x []f64, y []f64, n u32, incX u32, incY u32, ix u32, iy u32)

axpy_inc_to

fn axpy_unitary #

@[direct_array_access]
fn axpy_unitary(alpha f64, x []f64, mut y []f64)

axpy_unitary Length validation allows direct indexed access in the hot loop.

fn axpy_unitary_to #

@[direct_array_access]
fn axpy_unitary_to(mut dst []f64, alpha f64, x []f64, y []f64)

axpy_unitary_to Length validation allows direct indexed access in the hot loop.

fn close #

fn close(a f64, b f64) bool

close exposes this operation as part of the public API.

fn cos #

fn cos(x f64) f64

cos returns cos(x) rounded from the double-double evaluation; in practice this is the correctly rounded f64 value (see exp).

fn cos_dd #

fn cos_dd(x f64) (f64, f64)

cos_dd returns cos(x) as a double-double pair (hi, lo), with the same reduction domain and fallback as sin_dd.

fn cosh #

fn cosh(x f64) f64

cosh returns cosh(x) rounded from the double-double evaluation.

fn cosh_dd #

fn cosh_dd(x f64) (f64, f64)

cosh_dd returns cosh(x) as a double-double pair (hi, lo). For |x| > 710 it falls back to the libm value with lo = 0.

fn dot_compensated #

fn dot_compensated(x []f64, y []f64) f64

dot_compensated returns dot_dd rounded to a single f64 (hi + lo).

fn dot_dd #

@[direct_array_access]
fn dot_dd(x []f64, y []f64) (f64, f64)

dot_dd returns the double-double dot product (hi, lo) of x and y, with each product split exactly by two_prod before accumulation.

fn dot_inc #

fn dot_inc(x []f64, y []f64, n u32, incX u32, incY u32, ix u32, iy u32) f64

dot_inc

fn dot_unitary #

@[direct_array_access]
fn dot_unitary(x []f64, y []f64) f64

dot_unitary returns the f64 dot product, widening each block of products into four scalar accumulators so partial sums stay independent. Length validation allows direct indexed access in the hot loop.

fn equal_strided #

fn equal_strided(ref []f64, x []f64, inc int) bool

equal_strided returns true if the strided vector x contains elements of the dense vector ref at indices i*inc, false otherwise.

fn exp #

fn exp(x f64) f64

exp returns e^x rounded from the double-double evaluation; in practice this is the correctly rounded f64 value (see the module comment).

fn exp2 #

fn exp2(x f64) f64

exp2 returns 2^x rounded from the double-double evaluation.

fn exp2_dd #

fn exp2_dd(x f64) (f64, f64)

exp2_dd returns 2^x as a double-double pair (hi, lo).

fn exp_dd #

fn exp_dd(x f64) (f64, f64)

exp_dd returns e^x as a double-double pair (hi, lo).

fn expm1 #

fn expm1(x f64) f64

expm1 returns e^x - 1 rounded from the double-double evaluation.

fn expm1_dd #

fn expm1_dd(x f64) (f64, f64)

expm1_dd returns e^x - 1 as a double-double pair (hi, lo). It uses a dedicated e^r - 1 series after the ln(2) range reduction: computing exp_dd(x) first and subtracting 1 loses the last bit exactly in the hard cases the directed search found (x ~ 1e-16), because the exp pair near 1 has ~1e-33 absolute error while e^x - 1 is ~1e-16 there.

fn gemv_n #

fn gemv_n(m u32, n u32, alpha f64, a []f64, lda u32, x []f64, incx int, beta f64, mut y []f64, incy int)

gemv_n computes y = alpha * A * x + beta * y where A is an m×n dense matrix, x and y are vectors, and alpha and beta are scalars.

fn gemv_t #

fn gemv_t(m u32, n u32, alpha f64, a []f64, lda u32, x []f64, incx int, beta f64, mut y []f64, incy int)

gemv_t computes y = alpha * Aᵀ * x + beta * y where A is an m×n dense matrix, x and y are vectors, and alpha and beta are scalars.

fn ger #

fn ger(m u32, n u32, alpha f64, x []f64, incx u32, y []f64, incy u32, mut a []f64, lda u32)

ger performs the rank-one operation A += alpha * x * yᵀ where A is an m×n dense matrix, x and y are vectors, and alpha is a scalar.

fn guard_inc_vector #

fn guard_inc_vector(vec []f64, gd_val f64, inc int, gd_len int) []f64

guard_inc_vector copies the source vector (vec) into a new incremented slice with guards. End guards will be length gd_len. Internal and end guards will be filled with sigil value gd_val.

fn guard_vector #

fn guard_vector(vec []f64, gd_val f64, gd_ln int) []f64

guard_vector copies the source vector (vec) into a new slice with guards. Guards guarded[..gd_ln] and guarded[len-gd_ln..] will be filled with sigil value gd_val.

fn is_valid_guard #

fn is_valid_guard(vec []f64, gd_val f64, gd_ln int) bool

is_valid_guard will test for violated guards, generated by guard_vector.

fn is_valid_inc_guard #

fn is_valid_inc_guard(vec []f64, gd_val f64, inc int, gd_ln int) bool

is_valid_inc_guard will test for violated guards, generated by guard_inc_vector.

fn l2_distance_unitary #

fn l2_distance_unitary(x []f64, y []f64) f64

l2_distance_unitary returns the L2-norm of x-y.

fn l2_norm_inc #

fn l2_norm_inc(x []f64, n u32, incx u32) f64

l2_norm_inc returns the L2-norm of x.

fn l2_norm_unitary #

fn l2_norm_unitary(x []f64) f64

l2_norm_unitary returns the L2-norm of x.

fn log #

fn log(x f64) f64

log returns log(x) rounded from the double-double evaluation; in practice this is the correctly rounded f64 value (see exp).

fn log10 #

fn log10(x f64) f64

log10 returns log10(x) rounded from the double-double evaluation.

fn log10_dd #

fn log10_dd(x f64) (f64, f64)

log10_dd returns the base-10 logarithm of x as a double-double pair.

fn log1p #

fn log1p(x f64) f64

log1p returns log(1 + x) rounded from the double-double evaluation.

fn log1p_dd #

fn log1p_dd(x f64) (f64, f64)

log1p_dd returns log(1 + x) as a double-double pair (hi, lo). Near zero it uses the atanh series with 2 + x formed exactly as a double-double; away from zero it forms 1 + x exactly with two_sum and corrects log(s) by the residual. For x < -1 it returns NaN and for x = -1 it returns -inf, like math.log1p.

fn log2 #

fn log2(x f64) f64

log2 returns log2(x) rounded from the double-double evaluation.

fn log2_dd #

fn log2_dd(x f64) (f64, f64)

log2_dd returns the base-2 logarithm of x as a double-double pair.

fn log_dd #

fn log_dd(x f64) (f64, f64)

log_dd returns the natural logarithm of x as a double-double pair (hi, lo). For x <= 0 it returns the same special values as math.log.

fn new_guarded_vector #

fn new_guarded_vector(data []f64, inc int) ([]f64, []f64, []f64)

new_guarded_vector allocates a new slice and returns it as three subslices. v is a strided vector that contains elements of data at indices i*inc and nan elsewhere. frontGuard and backGuard are filled with nan values, and their backing arrays are directly adjacent to v in memory. The three slices can be used to detect invalid memory reads and writes.

fn non_strided_write #

fn non_strided_write(x []f64, inc int) bool

non_strided_write returns false if all elements of x at non-stride indices are equal to nan, true otherwise.

fn quick_two_sum #

fn quick_two_sum(a f64, b f64) (f64, f64)

quick_two_sum returns (s, e) with s + e == a + b exactly; requires |a| >= |b|.

fn random_slice #

fn random_slice(n int, inc int) []f64

random_slice exposes this operation as part of the public API.

fn same #

fn same(a f64, b f64) bool

same returns true when the inputs have the same value, allowing NaN equality.

fn scal_inc #

fn scal_inc(alpha f64, mut x []f64, n u32, incx u32)

scal_inc

fn scal_inc_to #

fn scal_inc_to(mut dst []f64, incdst u32, alpha f64, x []f64, n u32, incx u32)

scal_inc_to

fn scal_unitary #

fn scal_unitary(alpha f64, mut x []f64)

scal_unitary

fn scal_unitary_to #

fn scal_unitary_to(mut dst []f64, alpha f64, x []f64)

scal_unitary_to

fn sin #

fn sin(x f64) f64

sin returns sin(x) rounded from the double-double evaluation; in practice this is the correctly rounded f64 value (see exp).

fn sin_dd #

fn sin_dd(x f64) (f64, f64)

sin_dd returns sin(x) as a double-double pair (hi, lo). The argument reduction is double-double accurate for |x| <= 1e15; beyond that (and for non-finite inputs) it falls back to the libm value with lo = 0.

fn sinh #

fn sinh(x f64) f64

sinh returns sinh(x) rounded from the double-double evaluation.

fn sinh_dd #

fn sinh_dd(x f64) (f64, f64)

sinh_dd returns sinh(x) as a double-double pair (hi, lo). For |x| > 710 it falls back to the libm value with lo = 0.

fn soclose #

fn soclose(a f64, b f64, e_ f64) bool

soclose exposes this operation as part of the public API.

fn sum_compensated #

fn sum_compensated(x []f64) f64

sum_compensated returns sum_dd rounded to a single f64 (hi + lo).

fn sum_dd #

fn sum_dd(x []f64) (f64, f64)

sum_dd returns the double-double sum (hi, lo) of x: the exact sum of the inputs rounded to a hi part, with lo holding the residual. hi + lo approximates the true sum with roughly 106 bits of precision.

fn tan #

fn tan(x f64) f64

tan returns tan(x) rounded from the double-double evaluation.

fn tan_dd #

fn tan_dd(x f64) (f64, f64)

tan_dd returns tan(x) as a double-double pair (hi, lo), computed as sin_dd / cos_dd with the same reduction domain and fallback as sin_dd.

fn tanh #

fn tanh(x f64) f64

tanh returns tanh(x) rounded from the double-double evaluation.

fn tanh_dd #

fn tanh_dd(x f64) (f64, f64)

tanh_dd returns tanh(x) as a double-double pair (hi, lo), computed as (1 - d) / (1 + d) with d = e^(-2|x|): no overflow at any magnitude, and d underflows to 0 exactly when tanh rounds to +-1.

fn tolerance #

fn tolerance(a f64, b f64, tol f64) bool

tolerance exposes this operation as part of the public API.

fn two_prod #

fn two_prod(a f64, b f64) (f64, f64)

two_prod returns (p, e) with p = fl(a * b) and p + e == a * b exactly, using Dekker's splitting (no FMA required).

fn two_sum #

fn two_sum(a f64, b f64) (f64, f64)

two_sum returns (s, e) with s = fl(a + b) and s + e == a + b exactly, for any a and b (Knuth's TwoSum, no ordering requirement).

fn veryclose #

fn veryclose(a f64, b f64) bool

veryclose exposes this operation as part of the public API.

fn IncSet.new #

fn IncSet.new(inc ...int) []IncSet

IncSet.new will generate all (x,y) combinations of the input increment set.

fn IncToSet.new #

fn IncToSet.new(inc ...int) []IncToSet

IncToSet.new will generate all (dst,x,y) combinations of the input increment set.