Special Relativity in Financial Modeling 1.0.0
Lorentz transforms, spacetime classification, and geodesic price paths for quantitative finance
Loading...
Searching...
No Matches
gamma_scalar.cpp
Go to the documentation of this file.
1/**
2 * @file gamma_scalar.cpp
3 * @brief Scalar reference implementation of the gamma batch kernel.
4 *
5 * Module: src/simd/
6 * Owner: AGT-08 — 2026-03-01
7 *
8 * Responsibility
9 * --------------
10 * Compute gamma_i = 1.0 / sqrt(1.0 - betas[i]^2) for all i in [0, n).
11 * This is the authoritative reference implementation. All SIMD variants
12 * must produce results within 1 ULP of the scalar path for any valid input.
13 *
14 * Correctness Notes
15 * -----------------
16 * • Input betas are expected to be in [0, BETA_MAX_SAFE) — the same range
17 * accepted by BetaVelocity::make().
18 * • A defensive clamp to BETA_CLAMP_LIMIT is applied before the sqrt to
19 * ensure the argument of sqrt is strictly positive even in edge cases.
20 * • gamma ≥ 1.0 for all valid betas; the result is always finite.
21 */
22
23#include "simd_batch_detail.hpp"
24#include "momentum/momentum.hpp" // BETA_MAX_SAFE
25
26#include <cmath>
27
28namespace srfm::simd::detail {
29
30static constexpr double BETA_CLAMP_LIMIT =
32
34 const double* SRFM_RESTRICT betas,
35 std::size_t n,
36 double* SRFM_RESTRICT out) noexcept
37{
38 for (std::size_t i = 0; i < n; ++i) {
39 // Clamp to ensure sqrt argument > 0.
40 const double b = (betas[i] > BETA_CLAMP_LIMIT) ? BETA_CLAMP_LIMIT : betas[i];
41 const double b2 = b * b;
42 const double denom = 1.0 - b2; // in (0, 1] for valid betas
43 out[i] = 1.0 / std::sqrt(denom);
44 }
45}
46
47} // namespace srfm::simd::detail
constexpr double BETA_MAX_SAFE
Definition momentum.hpp:62
static constexpr double BETA_CLAMP_LIMIT
Definition beta_avx2.cpp:30
void compute_gamma_scalar(const double *__restrict__ betas, std::size_t n, double *__restrict__ out) noexcept
Scalar reference implementation of the gamma batch kernel.
Internal raw-double compute signatures for SIMD batch kernels.
#define SRFM_RESTRICT
Momentum-Velocity Signal Processor (AGT-03 / SRFM)