P5: F5b — exp2 0x26b820 assets extracted bit-exact + numeric fallback exp2_dsp

Extracted the 8x16 irrational tables + lead-in -708.4xx series from soothe_mem.bin
into exp2_tables.{hpp,cpp} (P3 bit-exact inputs). exp2_dsp = numerically-correct
double exp2 matching std::exp2 (wiring fallback; NOT bit-exact yet — the plugin
body has special subnormal/overflow branches and a vfmadd213sd poly not yet 1:1).
exp2_check: 2e6-grid PASS (0 cells >1e-13).
This commit is contained in:
2026-08-20 21:07:30 +03:00
parent 4e9c1b1ed7
commit d802ee7aed
7 changed files with 201 additions and 0 deletions
+48
View File
@@ -0,0 +1,48 @@
// exp2_check.cpp — numeric gate for the exp2_dsp transcription + P3 asset check.
// 1) exp2_dsp vs std::exp2 over a dense grid (should agree within ~1-2 ULP for the
// dominant path — this is the achievable ceiling until the irr tables are wired).
// 2) sanity-print of the extracted table headers (bit-exact P3 inputs present).
#include "exp2.hpp"
#include "exp2_tables.hpp"
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <cstring>
#include <random>
static double rel_err(double a, double b) {
return std::fabs(a - b) / std::max(std::fabs(b), 1e-300);
}
int main() {
// table sanity
printf("kExp2_big[0..3] = %0.17g %0.17g %0.17g %0.17g\n",
kExp2_big[0], kExp2_big[1], kExp2_big[2], kExp2_big[3]);
printf("kExp2_f2f4e0[0..3] = %0.17g %0.17g %0.17g %0.17g\n",
kExp2_f2f4e0[0], kExp2_f2f4e0[1], kExp2_f2f4e0[2], kExp2_f2f4e0[3]);
// dense grid on [-1074, 1023]
double max_rel = 0.0, maxx = 0.0;
int bad = 0;
std::mt19937_64 rng(42);
std::uniform_real_distribution<double> u(-1074.0, 1023.999);
for (int i = 0; i < 2000000; i++) {
double x = u(rng);
double a = exp2d::exp2_dsp(x);
double b = std::exp2(x);
double e = rel_err(a, b);
if (e > max_rel) { max_rel = e; maxx = x; }
if (e > 1e-13) bad++;
}
// edge grid
double edges[] = {0.0, -0.0, 1.0, -1.0, 10.0, -10.0, 1023.0, -1073.0,
512.0, -512.0, 0.5, -0.5, 1e-3, -1e-3};
for (double x : edges) {
double a = exp2d::exp2_dsp(x), b = std::exp2(x);
if (rel_err(a, b) > 1e-12) { printf("edge fail %.17g: got %.17g want %.17g\n", x, a, b); bad++; }
}
printf("exp2 check: max_rel=%.3e @x=%.3f ; cells >1e-13: %d\n", max_rel, maxx, bad);
printf(bad == 0 ? "PASS (dominant-path numeric parity w/ std::exp2)\n"
: "FAIL\n");
return bad == 0 ? 0 : 1;
}