@photivra/engine 2.4.1 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +53 -1
- package/CITATION.cff +1 -1
- package/README.md +6 -6
- package/SECURITY.md +1 -1
- package/THIRD_PARTY.md +1 -0
- package/dist/capture/native-environment-lean.d.ts +1 -1
- package/dist/capture/native-environment-lean.js +17 -3
- package/dist/capture/native-environment-lean.js.map +1 -1
- package/dist/capture/native-environment-raw.d.ts +0 -4
- package/dist/capture/native-environment-raw.js +6 -2
- package/dist/capture/native-environment-raw.js.map +1 -1
- package/dist/color/illuminants.d.ts +15 -0
- package/dist/color/illuminants.js +81 -24
- package/dist/color/illuminants.js.map +1 -1
- package/dist/color/srgb-transfer.d.ts +6 -0
- package/dist/color/srgb-transfer.js +9 -0
- package/dist/color/srgb-transfer.js.map +1 -1
- package/dist/color/white-balance.d.ts +6 -0
- package/dist/color/white-balance.js +15 -2
- package/dist/color/white-balance.js.map +1 -1
- package/dist/core/internal-radiance-evaluator.d.ts +6 -0
- package/dist/core/internal-radiance-evaluator.js +33 -0
- package/dist/core/internal-radiance-evaluator.js.map +1 -0
- package/dist/core/portable-math.d.ts +33 -0
- package/dist/core/portable-math.js +342 -0
- package/dist/core/portable-math.js.map +1 -1
- package/dist/core/version.d.ts +1 -1
- package/dist/core/version.js +1 -1
- package/dist/core/version.js.map +1 -1
- package/dist/facade/chart-scenes.d.ts +9 -0
- package/dist/facade/chart-scenes.js +17 -4
- package/dist/facade/chart-scenes.js.map +1 -1
- package/dist/facade/diffraction-provider.d.ts +10 -0
- package/dist/facade/diffraction-provider.js +38 -17
- package/dist/facade/diffraction-provider.js.map +1 -1
- package/dist/facade/display-view.d.ts +208 -0
- package/dist/facade/display-view.js +1461 -0
- package/dist/facade/display-view.js.map +1 -0
- package/dist/facade/scene-radiance.d.ts +7 -0
- package/dist/facade/scene-radiance.js +18 -5
- package/dist/facade/scene-radiance.js.map +1 -1
- package/dist/facade/simulate-capture.d.ts +229 -5
- package/dist/facade/simulate-capture.js +119 -35
- package/dist/facade/simulate-capture.js.map +1 -1
- package/dist/facade/simulate-display-view.d.ts +21 -0
- package/dist/facade/simulate-display-view.js +168 -0
- package/dist/facade/simulate-display-view.js.map +1 -0
- package/dist/facade/subject-framing.d.ts +78 -0
- package/dist/facade/subject-framing.js +69 -20
- package/dist/facade/subject-framing.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/optics/diffraction-psf-profile.d.ts +59 -3
- package/dist/optics/diffraction-psf-profile.js +147 -5
- package/dist/optics/diffraction-psf-profile.js.map +1 -1
- package/dist/optics/irradiance-convolution.js +1 -1
- package/dist/optics/irradiance-convolution.js.map +1 -1
- package/dist/optics/scene-to-sensor-irradiance.d.ts +7 -0
- package/dist/optics/scene-to-sensor-irradiance.js +10 -5
- package/dist/optics/scene-to-sensor-irradiance.js.map +1 -1
- package/dist/output/print-plan.d.ts +8 -1
- package/dist/output/print-plan.js +8 -1
- package/dist/output/print-plan.js.map +1 -1
- package/dist/schema/scene-radiance.d.ts +16 -0
- package/dist/schema/scene-radiance.js +25 -4
- package/dist/schema/scene-radiance.js.map +1 -1
- package/dist/sensor/raw-readout.d.ts +12 -0
- package/dist/sensor/raw-readout.js +131 -9
- package/dist/sensor/raw-readout.js.map +1 -1
- package/dist/sensor/stochastic-seed.d.ts +13 -0
- package/dist/sensor/stochastic-seed.js +42 -8
- package/dist/sensor/stochastic-seed.js.map +1 -1
- package/docs/AGENT_GUIDE.md +1 -0
- package/docs/API_REFERENCE.md +16 -1
- package/docs/QUICK_START.md +245 -9
- package/docs/USAGE.md +15 -0
- package/docs/api/core-version.md +1 -1
- package/docs/api/exports.json +37 -2
- package/docs/api/facade-simulate-capture.md +70 -2
- package/docs/api/facade-simulate-display-view.md +18 -0
- package/docs/api/facade-subject-framing.md +83 -0
- package/docs/api/optics-diffraction-psf-profile.md +8 -1
- package/docs/api/output-print-plan.md +8 -1
- package/package.json +3 -2
|
@@ -53,4 +53,346 @@ export function equalWithinUlps(a, b, maximumUlps) {
|
|
|
53
53
|
return true;
|
|
54
54
|
return Math.abs(a - b) <= maximumUlps * Number.EPSILON * Math.max(Math.abs(a), Math.abs(b));
|
|
55
55
|
}
|
|
56
|
+
// ---------------------------------------------------------------------------------------------------------------
|
|
57
|
+
// Portable logarithm, exponential, power, cube root and cosine/sine of 2πu.
|
|
58
|
+
//
|
|
59
|
+
// Each function below is a fixed sequence of correctly rounded binary64 operations (+, −, ×, ÷, exact
|
|
60
|
+
// power-of-two scaling through the IEEE 754 bit pattern, Math.round/Math.floor and integer operations), with
|
|
61
|
+
// every constant written as a decimal literal of at most 17 significant digits (ECMAScript converts these
|
|
62
|
+
// exactly to the nearest double). The bits of every result are therefore the same in every conforming
|
|
63
|
+
// JavaScript engine, unlike Math.pow, Math.exp, Math.log, Math.cbrt and Math.cos, which ECMA-262 leaves
|
|
64
|
+
// "implementation-approximated" (docs/NUMERICAL_CORRECTNESS.md, "Cross-engine determinism").
|
|
65
|
+
//
|
|
66
|
+
// Methods (textbook; no code copied):
|
|
67
|
+
// - Error-free transformations (double-double arithmetic): TwoSum (Knuth, The Art of Computer Programming
|
|
68
|
+
// vol. 2, §4.2.2), FastTwoSum and TwoProduct with Veltkamp's splitting (Dekker, "A floating-point technique
|
|
69
|
+
// for extending the available precision", Numerische Mathematik 18, 1971). Exact barring overflow and
|
|
70
|
+
// underflow, which the arguments here cannot reach.
|
|
71
|
+
// - log2(x): x = m·2^e with m in [√½, √2); ln m = 2·atanh(s) = 2(s + s³/3 + s⁵/5 + …), s = (m − 1)/(m + 1),
|
|
72
|
+
// |s| ≤ 0.1716 (J.-M. Muller, Elementary Functions: Algorithms and Implementation, 3rd ed., 2016, ch. 11).
|
|
73
|
+
// s carries a double-double correction; the series runs to s²³ (truncation below 2^-62 relative).
|
|
74
|
+
// - 2^t: t = n + r with n = round(t), |r| ≤ ½; 2^r = e^(r·ln 2) by its Taylor series to degree 14 (truncation
|
|
75
|
+
// below 2^-57 relative), then an exact scaling by 2^n (Muller, ch. 11, "additive range reduction").
|
|
76
|
+
// - x^y = 2^(y·log2 x) with log2 x and y·log2 x carried as double-double; e^x = 2^(x·log2 e) and
|
|
77
|
+
// ∛x = 2^(log2 x / 3) likewise; ln x = log2 x · ln 2; e^x − 1 by its Taylor series for |x| < 1.
|
|
78
|
+
// - cos(2πu), sin(2πu): u = q/4 + r with q = round(4u) and |r| ≤ ⅛ (exact), then the Taylor series of cos and
|
|
79
|
+
// sin of 2πr to degrees 18 and 19 (truncation below 2^-66).
|
|
80
|
+
//
|
|
81
|
+
// Error bounds (from the operation counts above): portableExp2, portableExp, portableLog, portableLog2 and
|
|
82
|
+
// portableCbrt within 1 ulp; portableExpm1 within 2 ulps; portablePow within 1 ulp for |y| ≤ 4 (the double-double
|
|
83
|
+
// logarithm has relative error below 2^-56, so the error of y·log2 x adds at most |y|·2^-57·ln 2 relative);
|
|
84
|
+
// portableCosTwoPi and portableSinTwoPi within 2 ulps. Checked against 60-digit decimal references (Python decimal)
|
|
85
|
+
// on 2·10⁵ pseudo-random arguments per function (6·10⁵ for portableLog; |y| ≤ 4 and y = 1/2.4, 1.4 for portablePow):
|
|
86
|
+
// largest errors 0.53 ulp (log, log2), 0.86 (exp2), 0.94 (exp, cbrt, pow), 0.97 (pow with y = 1/2.4), 1.59 (cos,
|
|
87
|
+
// sin of 2πu) and 1.66 (e^x − 1); spot values are in test/portable-math.test.ts. These are accuracy bounds;
|
|
88
|
+
// determinism does not depend on them.
|
|
89
|
+
/** Bit access to a double: the high 32-bit word is at index HIGH of the view (detected once, so either byte order works). */
|
|
90
|
+
// The tables and constants below are built by expressions marked pure (/* @__PURE__ */), so a bundler drops them from a
|
|
91
|
+
// bundle that uses none of the functions that read them (a capture-only bundle keeps only portableHypot and equalWithinUlps).
|
|
92
|
+
const BITS = /* @__PURE__ */ new Float64Array(1), WORDS = /* @__PURE__ */ (() => new Uint32Array(BITS.buffer))();
|
|
93
|
+
const HIGH = /* @__PURE__ */ (() => (new Uint8Array(new Uint16Array([1]).buffer)[0] === 1 ? 1 : 0))(), LOW = 1 - HIGH;
|
|
94
|
+
/** 2^k for every integer k in [−1074, 1023] at POW2[k + 1074], built by exact halving and doubling. */
|
|
95
|
+
const POW2 = /* @__PURE__ */ (() => {
|
|
96
|
+
const table = new Float64Array(2098);
|
|
97
|
+
table[1074] = 1;
|
|
98
|
+
for (let k = 1; k <= 1023; k++)
|
|
99
|
+
table[1074 + k] = table[1073 + k] * 2;
|
|
100
|
+
for (let k = 1; k <= 1074; k++)
|
|
101
|
+
table[1074 - k] = table[1075 - k] / 2;
|
|
102
|
+
return table;
|
|
103
|
+
})();
|
|
104
|
+
/** v·2^k for an integer k in [−1100, 1100]: one exact multiplication (a single rounding only when the result is subnormal). */
|
|
105
|
+
function scaleByPowerOfTwo(v, k) {
|
|
106
|
+
if (k > 1023)
|
|
107
|
+
return v * POW2[2097] * POW2[1074 + k - 1023];
|
|
108
|
+
if (k < -1074)
|
|
109
|
+
return v * POW2[1074 + k + 1074] * POW2[0]; // exact first factor (v·2^(k+1074) is normal), one rounding
|
|
110
|
+
return v * POW2[1074 + k];
|
|
111
|
+
}
|
|
112
|
+
// Double-double arithmetic, written out inline below (local variables only, which keeps it fast):
|
|
113
|
+
// - FastTwoSum (|a| ≥ |b| or a = 0): s = a + b, err = b − (s − a), so a + b = s + err exactly;
|
|
114
|
+
// - TwoSum (any a, b): s = a + b, b' = s − a, err = (a − (s − b')) + (b − b');
|
|
115
|
+
// - TwoProduct: p = a·b, err = ((ah·bh − p) + ah·bl + al·bh) + al·bl, with Veltkamp's split
|
|
116
|
+
// ah = c − (c − a), al = a − ah, c = (2^27 + 1)·a (and likewise for b), so a·b = p + err exactly.
|
|
117
|
+
const SPLITTER = 134217729; // 2^27 + 1 (Veltkamp)
|
|
118
|
+
const LN2_HI = 0.6931471805599453, LN2_LO = 2.3190468138462996e-17;
|
|
119
|
+
const LOG2E_HI = 1.4426950408889634, LOG2E_LO = 2.0355273740931033e-17;
|
|
120
|
+
const SQRT2 = 1.4142135623730951, TWO_POW_54 = 18014398509481984, MIN_NORMAL = 2.2250738585072014e-308;
|
|
121
|
+
/** Veltkamp halves of a constant (the same values the split gives at each use). */
|
|
122
|
+
function splitHigh(a) { const c = SPLITTER * a; return c - (c - a); }
|
|
123
|
+
const LN2_HI_H = /* @__PURE__ */ splitHigh(LN2_HI), LN2_HI_L = LN2_HI - LN2_HI_H, LOG2E_HI_H = /* @__PURE__ */ splitHigh(LOG2E_HI), LOG2E_HI_L = LOG2E_HI - LOG2E_HI_H;
|
|
124
|
+
/** The low part of the last double-double result (its high part is the return value). */
|
|
125
|
+
const LOW_PART = /* @__PURE__ */ new Float64Array(1);
|
|
126
|
+
/**
|
|
127
|
+
* log2 m for m in [√½, √2] by the atanh series to s²³ (no table): builds LOG2_TABLE once. Returns the high part, the low
|
|
128
|
+
* part in LOW_PART[0]; relative error below 2^-56.
|
|
129
|
+
*/
|
|
130
|
+
function log2SeriesDoubleDouble(x) {
|
|
131
|
+
let e = 0;
|
|
132
|
+
if (x < MIN_NORMAL) {
|
|
133
|
+
x *= TWO_POW_54;
|
|
134
|
+
e = -54;
|
|
135
|
+
}
|
|
136
|
+
BITS[0] = x;
|
|
137
|
+
const high = WORDS[HIGH];
|
|
138
|
+
e += (high >>> 20) - 1023;
|
|
139
|
+
let m = x * POW2[1074 - ((high >>> 20) - 1023)]; // exact: m in [1, 2)
|
|
140
|
+
if (m > SQRT2) {
|
|
141
|
+
m *= 0.5;
|
|
142
|
+
e += 1;
|
|
143
|
+
}
|
|
144
|
+
// s = f/(2 + f) with f = m − 1 (exact), as sHi + sLo: 2 + f = dh + dl exactly (FastTwoSum), then the residual
|
|
145
|
+
// f − sHi·(dh + dl) with sHi·dh = p + pe exactly (TwoProduct).
|
|
146
|
+
const f = m - 1, dh = 2 + f, dl = f - (dh - 2), sHi = f / dh, p = sHi * dh;
|
|
147
|
+
let c = SPLITTER * sHi;
|
|
148
|
+
const ah = c - (c - sHi), al = sHi - ah;
|
|
149
|
+
c = SPLITTER * dh;
|
|
150
|
+
const bh = c - (c - dh), bl = dh - bh, pe = ((ah * bh - p) + ah * bl + al * bh) + al * bl;
|
|
151
|
+
const sLo = (((f - p) - pe) - sHi * dl) / dh;
|
|
152
|
+
const z = sHi * sHi;
|
|
153
|
+
const tail = sHi * z * (0.6666666666666666 + z * (0.4 + z * (0.2857142857142857 + z * (0.2222222222222222 + z * (0.18181818181818182 + z * (0.15384615384615385 +
|
|
154
|
+
z * (0.13333333333333333 + z * (0.11764705882352941 + z * (0.10526315789473684 + z * (0.09523809523809523 + z * 0.08695652173913043))))))))));
|
|
155
|
+
// ln m = 2sHi + (2sLo + tail) = lh + ll (FastTwoSum); times log2 e = LOG2E_HI + LOG2E_LO (TwoProduct of the high parts); plus e (TwoSum).
|
|
156
|
+
const a1 = 2 * sHi, b1 = 2 * sLo + tail, lh = a1 + b1, ll = b1 - (lh - a1), q = lh * LOG2E_HI;
|
|
157
|
+
c = SPLITTER * lh;
|
|
158
|
+
const ch = c - (c - lh), cl = lh - ch, qe = ((ch * LOG2E_HI_H - q) + ch * LOG2E_HI_L + cl * LOG2E_HI_H) + cl * LOG2E_HI_L;
|
|
159
|
+
const pl = qe + (lh * LOG2E_LO + ll * LOG2E_HI);
|
|
160
|
+
const t = e + q, tb = t - e, te = (e - (t - tb)) + (q - tb), b2 = te + pl, hi = t + b2;
|
|
161
|
+
LOW_PART[0] = b2 - (hi - t);
|
|
162
|
+
return hi;
|
|
163
|
+
}
|
|
164
|
+
/** log2(k/128) for k = 90 … 182 (the table's range of k = round(128·m), m in [√½, √2]) as double-doubles. */
|
|
165
|
+
const LOG2_TABLE_LO = /* @__PURE__ */ new Float64Array(183);
|
|
166
|
+
const LOG2_TABLE_HI = /* @__PURE__ */ (() => {
|
|
167
|
+
const table = new Float64Array(183);
|
|
168
|
+
for (let k = 90; k <= 182; k++) {
|
|
169
|
+
table[k] = log2SeriesDoubleDouble(k / 128);
|
|
170
|
+
LOG2_TABLE_LO[k] = LOW_PART[0];
|
|
171
|
+
}
|
|
172
|
+
return table;
|
|
173
|
+
})();
|
|
174
|
+
/**
|
|
175
|
+
* log2 x as a double-double for finite x > 0: returns the high part, the low part in LOW_PART[0]. x = m·2^e with m in
|
|
176
|
+
* [√½, √2]; m = F·(1 + f/F) with F = k/128, k = round(128·m), so log2 m = log2 F (table) + 2·atanh(s)·log2 e with
|
|
177
|
+
* s = f/(m + F), |s| < 2^-8.4, by its series to s⁷ (truncation below 2^-70 relative). Relative error below 2^-56.
|
|
178
|
+
*/
|
|
179
|
+
function log2DoubleDouble(x) {
|
|
180
|
+
let e = 0;
|
|
181
|
+
if (x < MIN_NORMAL) {
|
|
182
|
+
x *= TWO_POW_54;
|
|
183
|
+
e = -54;
|
|
184
|
+
}
|
|
185
|
+
BITS[0] = x;
|
|
186
|
+
const high = WORDS[HIGH];
|
|
187
|
+
e += (high >>> 20) - 1023;
|
|
188
|
+
let m = x * POW2[1074 - ((high >>> 20) - 1023)]; // exact: m in [1, 2)
|
|
189
|
+
if (m > SQRT2) {
|
|
190
|
+
m *= 0.5;
|
|
191
|
+
e += 1;
|
|
192
|
+
}
|
|
193
|
+
// F = k/128 (exact) and f = m − F (exact, F/2 ≤ m ≤ 2F); m + F = dh + dl exactly (TwoSum); s = f/(dh + dl) as sHi + sLo
|
|
194
|
+
// from the residual f − sHi·(dh + dl), with sHi·dh = p + pe exactly (TwoProduct).
|
|
195
|
+
const k = Math.round(m * 128), F = k / 128, f = m - F, dh = m + F, db = dh - m, dl = (m - (dh - db)) + (F - db);
|
|
196
|
+
const sHi = f / dh, p = sHi * dh;
|
|
197
|
+
let c = SPLITTER * sHi;
|
|
198
|
+
const ah = c - (c - sHi), al = sHi - ah;
|
|
199
|
+
c = SPLITTER * dh;
|
|
200
|
+
const bh = c - (c - dh), bl = dh - bh, pe = ((ah * bh - p) + ah * bl + al * bh) + al * bl;
|
|
201
|
+
const sLo = (((f - p) - pe) - sHi * dl) / dh, z = sHi * sHi;
|
|
202
|
+
const tail = sHi * z * (0.6666666666666666 + z * (0.4 + z * 0.2857142857142857));
|
|
203
|
+
// ln(m/F) = 2sHi + (2sLo + tail) = lh + ll (FastTwoSum); times log2 e = LOG2E_HI + LOG2E_LO (TwoProduct of the high
|
|
204
|
+
// parts); plus log2 F (TwoSum with the table's high part), then plus e (TwoSum).
|
|
205
|
+
const a1 = 2 * sHi, b1 = 2 * sLo + tail, lh = a1 + b1, ll = b1 - (lh - a1), q = lh * LOG2E_HI;
|
|
206
|
+
c = SPLITTER * lh;
|
|
207
|
+
const ch = c - (c - lh), cl = lh - ch, qe = ((ch * LOG2E_HI_H - q) + ch * LOG2E_HI_L + cl * LOG2E_HI_H) + cl * LOG2E_HI_L;
|
|
208
|
+
const pl = qe + (lh * LOG2E_LO + ll * LOG2E_HI), th = LOG2_TABLE_HI[k];
|
|
209
|
+
const t = th + q, tb = t - th, low = ((th - (t - tb)) + (q - tb)) + (pl + LOG2_TABLE_LO[k]);
|
|
210
|
+
const u = e + t, ub = u - e, b2 = ((e - (u - ub)) + (t - ub)) + low, hi = u + b2;
|
|
211
|
+
LOW_PART[0] = b2 - (hi - u);
|
|
212
|
+
return hi;
|
|
213
|
+
}
|
|
214
|
+
/** 2^(th + tl) for a double-double exponent; within 1 ulp (plus the error the exponent carries). */
|
|
215
|
+
function exp2DoubleDouble(th, tl) {
|
|
216
|
+
if (th !== th)
|
|
217
|
+
return NaN;
|
|
218
|
+
if (th > 1024)
|
|
219
|
+
return Infinity;
|
|
220
|
+
if (th < -1080)
|
|
221
|
+
return 0;
|
|
222
|
+
// th = n + r exactly (|r| ≤ ½); w = r·ln 2 = wh + wl (TwoProduct with LN2_HI, plus r·LN2_LO).
|
|
223
|
+
const n = Math.round(th), r = (th - n) + tl, wh = r * LN2_HI, c = SPLITTER * r, ah = c - (c - r), al = r - ah;
|
|
224
|
+
const wl = (((ah * LN2_HI_H - wh) + ah * LN2_HI_L + al * LN2_HI_H) + al * LN2_HI_L) + r * LN2_LO;
|
|
225
|
+
const q = 0.5 + wh * (0.16666666666666666 + wh * (0.041666666666666664 + wh * (0.008333333333333333 + wh * (0.001388888888888889 + wh * (0.0001984126984126984 +
|
|
226
|
+
wh * (2.48015873015873e-05 + wh * (2.7557319223985893e-06 + wh * (2.755731922398589e-07 + wh * (2.505210838544172e-08 + wh * (2.08767569878681e-09 +
|
|
227
|
+
wh * (1.6059043836821613e-10 + wh * 1.1470745597729725e-11)))))))))));
|
|
228
|
+
return scaleByPowerOfTwo(1 + (wh + (wl + wh * wh * q)), n);
|
|
229
|
+
}
|
|
230
|
+
/** log2 x, bit-identical in every JavaScript engine (within 1 ulp). 0 → −∞; negative or NaN → NaN; +∞ → +∞. */
|
|
231
|
+
export function portableLog2(x) {
|
|
232
|
+
if (!(x > 0))
|
|
233
|
+
return x === 0 ? -Infinity : NaN;
|
|
234
|
+
if (x === Infinity)
|
|
235
|
+
return Infinity;
|
|
236
|
+
const h = log2DoubleDouble(x);
|
|
237
|
+
return h + LOW_PART[0];
|
|
238
|
+
}
|
|
239
|
+
/** ln(k/128) for k = 90 … 182 as double-doubles (log2(k/128)·ln 2, TwoProduct with LN2_HI plus the small products). */
|
|
240
|
+
const LN_TABLE_LO = /* @__PURE__ */ new Float64Array(183);
|
|
241
|
+
const LN_TABLE_HI = /* @__PURE__ */ (() => {
|
|
242
|
+
const table = new Float64Array(183);
|
|
243
|
+
for (let k = 90; k <= 182; k++) {
|
|
244
|
+
const h = LOG2_TABLE_HI[k], l = LOG2_TABLE_LO[k], p = h * LN2_HI, c = SPLITTER * h, ah = c - (c - h), al = h - ah;
|
|
245
|
+
const pe = ((ah * LN2_HI_H - p) + ah * LN2_HI_L + al * LN2_HI_H) + al * LN2_HI_L, lo = pe + (h * LN2_LO + l * LN2_HI), hi = p + lo;
|
|
246
|
+
table[k] = hi;
|
|
247
|
+
LN_TABLE_LO[k] = lo - (hi - p);
|
|
248
|
+
}
|
|
249
|
+
return table;
|
|
250
|
+
})();
|
|
251
|
+
/** ln 2 = LN2_E_HI + LN2_E_LO with the low 32 bits of LN2_E_HI zero, so e·LN2_E_HI is exact for every exponent e here. */
|
|
252
|
+
const LN2_E_HI = /* @__PURE__ */ (() => { BITS[0] = LN2_HI; WORDS[LOW] = 0; return BITS[0]; })(), LN2_E_LO = (LN2_HI - LN2_E_HI) + LN2_LO;
|
|
253
|
+
/**
|
|
254
|
+
* Natural logarithm, bit-identical in every JavaScript engine (within 1 ulp). 0 → −∞; negative or NaN → NaN; +∞ → +∞.
|
|
255
|
+
* x = m·2^e, m in [√½, √2]; ln x = e·ln 2 + ln F (table, F = k/128, k = round(128·m)) + 2·atanh(s), s = (m − F)/(m + F),
|
|
256
|
+
* with s as a double-double and the three terms added with TwoSum.
|
|
257
|
+
*/
|
|
258
|
+
export function portableLog(x) {
|
|
259
|
+
if (!(x > 0))
|
|
260
|
+
return x === 0 ? -Infinity : NaN;
|
|
261
|
+
if (x === Infinity)
|
|
262
|
+
return Infinity;
|
|
263
|
+
let e = 0;
|
|
264
|
+
if (x < MIN_NORMAL) {
|
|
265
|
+
x *= TWO_POW_54;
|
|
266
|
+
e = -54;
|
|
267
|
+
}
|
|
268
|
+
BITS[0] = x;
|
|
269
|
+
const high = WORDS[HIGH];
|
|
270
|
+
e += (high >>> 20) - 1023;
|
|
271
|
+
let m = x * POW2[1074 - ((high >>> 20) - 1023)]; // exact: m in [1, 2)
|
|
272
|
+
if (m > SQRT2) {
|
|
273
|
+
m *= 0.5;
|
|
274
|
+
e += 1;
|
|
275
|
+
}
|
|
276
|
+
const k = Math.round(m * 128), F = k / 128, f = m - F, dh = m + F, db = dh - m, dl = (m - (dh - db)) + (F - db);
|
|
277
|
+
const sHi = f / dh, p = sHi * dh;
|
|
278
|
+
let c = SPLITTER * sHi;
|
|
279
|
+
const ah = c - (c - sHi), al = sHi - ah;
|
|
280
|
+
c = SPLITTER * dh;
|
|
281
|
+
const bh = c - (c - dh), bl = dh - bh, pe = ((ah * bh - p) + ah * bl + al * bh) + al * bl;
|
|
282
|
+
const sLo = (((f - p) - pe) - sHi * dl) / dh, z = sHi * sHi;
|
|
283
|
+
const tail = sHi * z * (0.6666666666666666 + z * (0.4 + z * 0.2857142857142857));
|
|
284
|
+
// (e·LN2_E_HI + ln F) + 2sHi with TwoSum errors, then the low parts.
|
|
285
|
+
const A = e * LN2_E_HI, B = LN_TABLE_HI[k], t = A + B, tb = t - A, te = (A - (t - tb)) + (B - tb);
|
|
286
|
+
const a2 = 2 * sHi, u = t + a2, ub = u - t, ue = (t - (u - ub)) + (a2 - ub);
|
|
287
|
+
return u + ((te + ue) + ((e * LN2_E_LO + LN_TABLE_LO[k]) + (2 * sLo + tail)));
|
|
288
|
+
}
|
|
289
|
+
/** 2^x, bit-identical in every JavaScript engine (within 1 ulp). */
|
|
290
|
+
export function portableExp2(x) { return exp2DoubleDouble(x, 0); }
|
|
291
|
+
/** e^x, bit-identical in every JavaScript engine (within 1 ulp). */
|
|
292
|
+
export function portableExp(x) {
|
|
293
|
+
if (x !== x)
|
|
294
|
+
return NaN;
|
|
295
|
+
if (x > 710)
|
|
296
|
+
return Infinity;
|
|
297
|
+
if (x < -746)
|
|
298
|
+
return 0;
|
|
299
|
+
// x·log2 e = th + tl: x·LOG2E_HI = th + te exactly (TwoProduct), plus x·LOG2E_LO.
|
|
300
|
+
const th = x * LOG2E_HI, c = SPLITTER * x, ah = c - (c - x), al = x - ah;
|
|
301
|
+
const te = ((ah * LOG2E_HI_H - th) + ah * LOG2E_HI_L + al * LOG2E_HI_H) + al * LOG2E_HI_L;
|
|
302
|
+
return exp2DoubleDouble(th, te + x * LOG2E_LO);
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* e^x − 1, bit-identical in every JavaScript engine (within 2 ulps): the Taylor series to degree 20 for |x| < 1
|
|
306
|
+
* (truncation below 2^-60 relative), else portableExp(x) − 1.
|
|
307
|
+
*/
|
|
308
|
+
export function portableExpm1(x) {
|
|
309
|
+
if (x !== x)
|
|
310
|
+
return NaN;
|
|
311
|
+
if (x === 0)
|
|
312
|
+
return x;
|
|
313
|
+
if (!(x > -1 && x < 1))
|
|
314
|
+
return portableExp(x) - 1;
|
|
315
|
+
return x + x * x * (0.5 + x * (0.16666666666666666 + x * (0.041666666666666664 + x * (0.008333333333333333 + x * (0.001388888888888889 + x * (0.0001984126984126984 +
|
|
316
|
+
x * (2.48015873015873e-05 + x * (2.7557319223985893e-06 + x * (2.755731922398589e-07 + x * (2.505210838544172e-08 + x * (2.08767569878681e-09 +
|
|
317
|
+
x * (1.6059043836821613e-10 + x * (1.1470745597729725e-11 + x * (7.647163731819816e-13 + x * (4.779477332387385e-14 + x * (2.8114572543455206e-15 +
|
|
318
|
+
x * (1.5619206968586225e-16 + x * (8.22063524662433e-18 + x * 4.110317623312165e-19))))))))))))))))));
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* x^y for x ≥ 0 and finite y, bit-identical in every JavaScript engine (within 1 ulp for |y| ≤ 4). x = 0 gives 0 for
|
|
322
|
+
* y > 0, 1 for y = 0 and +∞ for y < 0; negative x or a non-finite argument gives NaN (the callers never pass them).
|
|
323
|
+
*/
|
|
324
|
+
export function portablePow(x, y) {
|
|
325
|
+
if (!(x >= 0) || !Number.isFinite(x) || !Number.isFinite(y))
|
|
326
|
+
return NaN;
|
|
327
|
+
if (y === 0 || x === 1)
|
|
328
|
+
return 1;
|
|
329
|
+
if (x === 0)
|
|
330
|
+
return y > 0 ? 0 : Infinity;
|
|
331
|
+
// y·(lh + ll): lh·y = p + pe exactly (TwoProduct), then FastTwoSum(p, pe + ll·y).
|
|
332
|
+
const lh = log2DoubleDouble(x), ll = LOW_PART[0], p = lh * y;
|
|
333
|
+
let c = SPLITTER * lh;
|
|
334
|
+
const ah = c - (c - lh), al = lh - ah;
|
|
335
|
+
c = SPLITTER * y;
|
|
336
|
+
const bh = c - (c - y), bl = y - bh, pe = ((ah * bh - p) + ah * bl + al * bh) + al * bl;
|
|
337
|
+
const b = pe + ll * y, th = p + b;
|
|
338
|
+
return exp2DoubleDouble(th, b - (th - p));
|
|
339
|
+
}
|
|
340
|
+
/** ∛(2^r) for r = 0, 1, 2 (only scale the cube root's starting value, so their last bits do not matter). */
|
|
341
|
+
const CBRT_POWERS_OF_TWO = [1, 1.2599210498948732, 1.5874010519681994];
|
|
342
|
+
/**
|
|
343
|
+
* Cube root, bit-identical in every JavaScript engine (within 1 ulp; exact for ±0, ±∞ and cubes of powers of two).
|
|
344
|
+
* |x| = m·2^(3q + r) with m in [1, 2) and r in {0, 1, 2}, w = m·2^r: a cubic fit to ∛m (within 1.7·10⁻⁴) times ∛(2^r),
|
|
345
|
+
* one Halley step y ← y(y³ + 2w)/(2y³ + w) (cubic convergence: below 10⁻¹¹), then one Newton step y + (w − y³)/(3y²)
|
|
346
|
+
* with w − y³ formed exactly (TwoProduct), which leaves only the final rounding and errors near 10⁻²².
|
|
347
|
+
*/
|
|
348
|
+
export function portableCbrt(x) {
|
|
349
|
+
if (x === 0 || x !== x || !Number.isFinite(x))
|
|
350
|
+
return x;
|
|
351
|
+
let a = x < 0 ? -x : x, shift = 0;
|
|
352
|
+
if (a < MIN_NORMAL) {
|
|
353
|
+
a *= TWO_POW_54;
|
|
354
|
+
shift = -18;
|
|
355
|
+
}
|
|
356
|
+
BITS[0] = a;
|
|
357
|
+
const high = WORDS[HIGH], e = (high >>> 20) - 1023, q = Math.floor(e / 3), r = e - 3 * q;
|
|
358
|
+
const m = a * POW2[1074 - e], w = m * CBRT_SCALE[r]; // exact: m in [1, 2)
|
|
359
|
+
let y = (0.5561432746078446 + m * (0.5806821751356804 + m * (-0.15894786280039686 + m * 0.022291567104952514))) * CBRT_POWERS_OF_TWO[r];
|
|
360
|
+
const y3 = y * y * y;
|
|
361
|
+
y = y * (y3 + 2 * w) / (2 * y3 + w);
|
|
362
|
+
// y² = p + pe exactly; y³ = p·y + pe·y = t + te (TwoProduct of p and y, plus pe·y); w − y³ = (w − t) − te.
|
|
363
|
+
const p = y * y;
|
|
364
|
+
let c = SPLITTER * y;
|
|
365
|
+
const yh = c - (c - y), yl = y - yh, pe = ((yh * yh - p) + yh * yl + yl * yh) + yl * yl, t = p * y;
|
|
366
|
+
c = SPLITTER * p;
|
|
367
|
+
const ph = c - (c - p), pll = p - ph, te = (((ph * yh - t) + ph * yl + pll * yh) + pll * yl) + pe * y;
|
|
368
|
+
const root = scaleByPowerOfTwo(y + ((w - t) - te) / (3 * p), q + shift);
|
|
369
|
+
return x < 0 ? -root : root;
|
|
370
|
+
}
|
|
371
|
+
/** 2^r for r = 0, 1, 2. */
|
|
372
|
+
const CBRT_SCALE = [1, 2, 4];
|
|
373
|
+
/** cos(2πr) and sin(2πr) for |r| ≤ ⅛ (Taylor series in z = r²). */
|
|
374
|
+
function cosTwoPiReduced(r) {
|
|
375
|
+
const z = r * r;
|
|
376
|
+
return 1 + z * (-19.739208802178716 + z * (64.9393940226683 + z * (-85.45681720669373 + z * (60.24464137187666 + z * (-26.4262567833744 + z * (7.903536371318469 +
|
|
377
|
+
z * (-1.714390711088672 + z * (0.28200596845579123 + z * -0.03638284114254567))))))));
|
|
378
|
+
}
|
|
379
|
+
function sinTwoPiReduced(r) {
|
|
380
|
+
const z = r * r;
|
|
381
|
+
return r * (6.283185307179586 + z * (-41.34170224039976 + z * (81.60524927607506 + z * (-76.70585975306139 + z * (42.058693944897655 + z * (-15.09464257682299 +
|
|
382
|
+
z * (3.819952584848282 + z * (-0.7181223017785006 + z * (0.10422916220813984 + z * -0.012031585942120627)))))))));
|
|
383
|
+
}
|
|
384
|
+
/** cos(2πu) for finite u (u in turns), bit-identical in every JavaScript engine (within 2 ulps). */
|
|
385
|
+
export function portableCosTwoPi(u) {
|
|
386
|
+
if (!Number.isFinite(u))
|
|
387
|
+
return NaN;
|
|
388
|
+
const t = 4 * u, q = Math.round(t), r = (t - q) / 4, quadrant = ((q % 4) + 4) % 4;
|
|
389
|
+
return quadrant === 0 ? cosTwoPiReduced(r) : quadrant === 1 ? -sinTwoPiReduced(r) : quadrant === 2 ? -cosTwoPiReduced(r) : sinTwoPiReduced(r);
|
|
390
|
+
}
|
|
391
|
+
/** sin(2πu) for finite u (u in turns), bit-identical in every JavaScript engine (within 2 ulps). */
|
|
392
|
+
export function portableSinTwoPi(u) {
|
|
393
|
+
if (!Number.isFinite(u))
|
|
394
|
+
return NaN;
|
|
395
|
+
const t = 4 * u, q = Math.round(t), r = (t - q) / 4, quadrant = ((q % 4) + 4) % 4;
|
|
396
|
+
return quadrant === 0 ? sinTwoPiReduced(r) : quadrant === 1 ? cosTwoPiReduced(r) : quadrant === 2 ? -sinTwoPiReduced(r) : -cosTwoPiReduced(r);
|
|
397
|
+
}
|
|
56
398
|
//# sourceMappingURL=portable-math.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"portable-math.js","sourceRoot":"","sources":["../../src/core/portable-math.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC;;;;;;;;;;;;GAYG;AAEH,MAAM,KAAK,GAAG,CAAC,IAAI,GAAG,CAAC;AACvB,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC;AACxB,MAAM,UAAU,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC;AAC7B,MAAM,QAAQ,GAAG,CAAC,IAAI,GAAG,CAAC;AAE1B;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,GAAG,MAAyB;IACxD,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAClC,IAAI,CAAC,CAAC,SAAS,IAAI,OAAO,CAAC;YAAE,OAAO,GAAG,SAAS,CAAC;IACnD,CAAC;IACD,IAAI,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;QAAE,OAAO,OAAO,CAAC;IAC/D,MAAM,KAAK,GAAG,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5E,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,MAAM,GAAG,KAAK,GAAG,KAAK,CAAC;QAC7B,GAAG,IAAI,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IACD,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAChC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,CAAS,EAAE,CAAS,EAAE,WAAmB;IACvE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IAC7D,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACzB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,WAAW,GAAG,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9F,CAAC","sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Floating-point helpers that give bit-identical results in every JavaScript engine.\n *\n * ECMAScript requires `+ - * /` and `Math.sqrt` to be correctly rounded IEEE 754 binary64\n * (double-precision) operations. A fixed sequence of them gives the same bits in every\n * conforming engine. `Math.hypot`, `Math.exp`, `Math.atan`, `Math.cos` and the other\n * transcendental functions are \"implementation-approximated\" (ECMA-262 §21.3.2). They can\n * differ in the last bit between V8, JavaScriptCore and SpiderMonkey.\n *\n * So any value that is stored and later recomputed for an exact identity check must use\n * only the correctly rounded operations.\n * @see docs/NUMERICAL_CORRECTNESS.md §Cross-engine determinism\n */\n\nconst LARGE = 2 ** 500;\nconst SMALL = 2 ** -500;\nconst SCALE_DOWN = 2 ** -600;\nconst SCALE_UP = 2 ** 600;\n\n/**\n * Euclidean norm (vector length) of the components. Unlike `Math.hypot`, it uses only correctly\n * rounded IEEE operations, so the result is bit-identical in every JavaScript engine.\n *\n * Components are summed in argument order. Inputs far from 1 are first rescaled by an exact power\n * of two, so squaring cannot overflow or underflow. Non-finite input gives a non-finite result;\n * callers validate inputs first.\n */\nexport function portableHypot(...values: readonly number[]): number {\n let maximum = 0;\n for (const value of values) {\n const magnitude = Math.abs(value);\n if (!(magnitude <= maximum)) maximum = magnitude;\n }\n if (maximum === 0 || !Number.isFinite(maximum)) return maximum;\n const scale = maximum > LARGE ? SCALE_DOWN : maximum < SMALL ? SCALE_UP : 1;\n let sum = 0;\n for (const value of values) {\n const scaled = value * scale;\n sum += scaled * scaled;\n }\n return Math.sqrt(sum) / scale;\n}\n\n/**\n * True when two finite numbers differ by at most `maximumUlps` ULPs (units in the last place).\n * One ULP here is `Number.EPSILON` times the larger magnitude. Use it to accept an archived value\n * that another engine or an earlier release computed with an implementation-approximated function.\n */\nexport function equalWithinUlps(a: number, b: number, maximumUlps: number): boolean {\n if (!Number.isFinite(a) || !Number.isFinite(b)) return false;\n if (a === b) return true;\n return Math.abs(a - b) <= maximumUlps * Number.EPSILON * Math.max(Math.abs(a), Math.abs(b));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"portable-math.js","sourceRoot":"","sources":["../../src/core/portable-math.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC;;;;;;;;;;;;GAYG;AAEH,MAAM,KAAK,GAAG,CAAC,IAAI,GAAG,CAAC;AACvB,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC;AACxB,MA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Apache-2.0\n\n/**\n * Floating-point helpers that give bit-identical results in every JavaScript engine.\n *\n * ECMAScript requires `+ - * /` and `Math.sqrt` to be correctly rounded IEEE 754 binary64\n * (double-precision) operations. A fixed sequence of them gives the same bits in every\n * conforming engine. `Math.hypot`, `Math.exp`, `Math.atan`, `Math.cos` and the other\n * transcendental functions are \"implementation-approximated\" (ECMA-262 §21.3.2). They can\n * differ in the last bit between V8, JavaScriptCore and SpiderMonkey.\n *\n * So any value that is stored and later recomputed for an exact identity check must use\n * only the correctly rounded operations.\n * @see docs/NUMERICAL_CORRECTNESS.md §Cross-engine determinism\n */\n\nconst LARGE = 2 ** 500;\nconst SMALL = 2 ** -500;\nconst SCALE_DOWN = 2 ** -600;\nconst SCALE_UP = 2 ** 600;\n\n/**\n * Euclidean norm (vector length) of the components. Unlike `Math.hypot`, it uses only correctly\n * rounded IEEE operations, so the result is bit-identical in every JavaScript engine.\n *\n * Components are summed in argument order. Inputs far from 1 are first rescaled by an exact power\n * of two, so squaring cannot overflow or underflow. Non-finite input gives a non-finite result;\n * callers validate inputs first.\n */\nexport function portableHypot(...values: readonly number[]): number {\n let maximum = 0;\n for (const value of values) {\n const magnitude = Math.abs(value);\n if (!(magnitude <= maximum)) maximum = magnitude;\n }\n if (maximum === 0 || !Number.isFinite(maximum)) return maximum;\n const scale = maximum > LARGE ? SCALE_DOWN : maximum < SMALL ? SCALE_UP : 1;\n let sum = 0;\n for (const value of values) {\n const scaled = value * scale;\n sum += scaled * scaled;\n }\n return Math.sqrt(sum) / scale;\n}\n\n/**\n * True when two finite numbers differ by at most `maximumUlps` ULPs (units in the last place).\n * One ULP here is `Number.EPSILON` times the larger magnitude. Use it to accept an archived value\n * that another engine or an earlier release computed with an implementation-approximated function.\n */\nexport function equalWithinUlps(a: number, b: number, maximumUlps: number): boolean {\n if (!Number.isFinite(a) || !Number.isFinite(b)) return false;\n if (a === b) return true;\n return Math.abs(a - b) <= maximumUlps * Number.EPSILON * Math.max(Math.abs(a), Math.abs(b));\n}\n\n// ---------------------------------------------------------------------------------------------------------------\n// Portable logarithm, exponential, power, cube root and cosine/sine of 2πu.\n//\n// Each function below is a fixed sequence of correctly rounded binary64 operations (+, −, ×, ÷, exact\n// power-of-two scaling through the IEEE 754 bit pattern, Math.round/Math.floor and integer operations), with\n// every constant written as a decimal literal of at most 17 significant digits (ECMAScript converts these\n// exactly to the nearest double). The bits of every result are therefore the same in every conforming\n// JavaScript engine, unlike Math.pow, Math.exp, Math.log, Math.cbrt and Math.cos, which ECMA-262 leaves\n// \"implementation-approximated\" (docs/NUMERICAL_CORRECTNESS.md, \"Cross-engine determinism\").\n//\n// Methods (textbook; no code copied):\n// - Error-free transformations (double-double arithmetic): TwoSum (Knuth, The Art of Computer Programming\n// vol. 2, §4.2.2), FastTwoSum and TwoProduct with Veltkamp's splitting (Dekker, \"A floating-point technique\n// for extending the available precision\", Numerische Mathematik 18, 1971). Exact barring overflow and\n// underflow, which the arguments here cannot reach.\n// - log2(x): x = m·2^e with m in [√½, √2); ln m = 2·atanh(s) = 2(s + s³/3 + s⁵/5 + …), s = (m − 1)/(m + 1),\n// |s| ≤ 0.1716 (J.-M. Muller, Elementary Functions: Algorithms and Implementation, 3rd ed., 2016, ch. 11).\n// s carries a double-double correction; the series runs to s²³ (truncation below 2^-62 relative).\n// - 2^t: t = n + r with n = round(t), |r| ≤ ½; 2^r = e^(r·ln 2) by its Taylor series to degree 14 (truncation\n// below 2^-57 relative), then an exact scaling by 2^n (Muller, ch. 11, \"additive range reduction\").\n// - x^y = 2^(y·log2 x) with log2 x and y·log2 x carried as double-double; e^x = 2^(x·log2 e) and\n// ∛x = 2^(log2 x / 3) likewise; ln x = log2 x · ln 2; e^x − 1 by its Taylor series for |x| < 1.\n// - cos(2πu), sin(2πu): u = q/4 + r with q = round(4u) and |r| ≤ ⅛ (exact), then the Taylor series of cos and\n// sin of 2πr to degrees 18 and 19 (truncation below 2^-66).\n//\n// Error bounds (from the operation counts above): portableExp2, portableExp, portableLog, portableLog2 and\n// portableCbrt within 1 ulp; portableExpm1 within 2 ulps; portablePow within 1 ulp for |y| ≤ 4 (the double-double\n// logarithm has relative error below 2^-56, so the error of y·log2 x adds at most |y|·2^-57·ln 2 relative);\n// portableCosTwoPi and portableSinTwoPi within 2 ulps. Checked against 60-digit decimal references (Python decimal)\n// on 2·10⁵ pseudo-random arguments per function (6·10⁵ for portableLog; |y| ≤ 4 and y = 1/2.4, 1.4 for portablePow):\n// largest errors 0.53 ulp (log, log2), 0.86 (exp2), 0.94 (exp, cbrt, pow), 0.97 (pow with y = 1/2.4), 1.59 (cos,\n// sin of 2πu) and 1.66 (e^x − 1); spot values are in test/portable-math.test.ts. These are accuracy bounds;\n// determinism does not depend on them.\n\n/** Bit access to a double: the high 32-bit word is at index HIGH of the view (detected once, so either byte order works). */\n// The tables and constants below are built by expressions marked pure (/* @__PURE__ */), so a bundler drops them from a\n// bundle that uses none of the functions that read them (a capture-only bundle keeps only portableHypot and equalWithinUlps).\nconst BITS = /* @__PURE__ */ new Float64Array(1), WORDS = /* @__PURE__ */ ((): Uint32Array => new Uint32Array(BITS.buffer))();\nconst HIGH = /* @__PURE__ */ ((): number => (new Uint8Array(new Uint16Array([1]).buffer)[0] === 1 ? 1 : 0))(), LOW = 1 - HIGH;\n/** 2^k for every integer k in [−1074, 1023] at POW2[k + 1074], built by exact halving and doubling. */\nconst POW2 = /* @__PURE__ */ ((): Float64Array => {\n const table = new Float64Array(2098);\n table[1074] = 1;\n for (let k = 1; k <= 1023; k++) table[1074 + k] = table[1073 + k]! * 2;\n for (let k = 1; k <= 1074; k++) table[1074 - k] = table[1075 - k]! / 2;\n return table;\n})();\n/** v·2^k for an integer k in [−1100, 1100]: one exact multiplication (a single rounding only when the result is subnormal). */\nfunction scaleByPowerOfTwo(v: number, k: number): number {\n if (k > 1023) return v * POW2[2097]! * POW2[1074 + k - 1023]!;\n if (k < -1074) return v * POW2[1074 + k + 1074]! * POW2[0]!; // exact first factor (v·2^(k+1074) is normal), one rounding\n return v * POW2[1074 + k]!;\n}\n// Double-double arithmetic, written out inline below (local variables only, which keeps it fast):\n// - FastTwoSum (|a| ≥ |b| or a = 0): s = a + b, err = b − (s − a), so a + b = s + err exactly;\n// - TwoSum (any a, b): s = a + b, b' = s − a, err = (a − (s − b')) + (b − b');\n// - TwoProduct: p = a·b, err = ((ah·bh − p) + ah·bl + al·bh) + al·bl, with Veltkamp's split\n// ah = c − (c − a), al = a − ah, c = (2^27 + 1)·a (and likewise for b), so a·b = p + err exactly.\nconst SPLITTER = 134217729; // 2^27 + 1 (Veltkamp)\nconst LN2_HI = 0.6931471805599453, LN2_LO = 2.3190468138462996e-17;\nconst LOG2E_HI = 1.4426950408889634, LOG2E_LO = 2.0355273740931033e-17;\nconst SQRT2 = 1.4142135623730951, TWO_POW_54 = 18014398509481984, MIN_NORMAL = 2.2250738585072014e-308;\n/** Veltkamp halves of a constant (the same values the split gives at each use). */\nfunction splitHigh(a: number): number { const c = SPLITTER * a; return c - (c - a); }\nconst LN2_HI_H = /* @__PURE__ */ splitHigh(LN2_HI), LN2_HI_L = LN2_HI - LN2_HI_H, LOG2E_HI_H = /* @__PURE__ */ splitHigh(LOG2E_HI), LOG2E_HI_L = LOG2E_HI - LOG2E_HI_H;\n/** The low part of the last double-double result (its high part is the return value). */\nconst LOW_PART = /* @__PURE__ */ new Float64Array(1);\n\n/**\n * log2 m for m in [√½, √2] by the atanh series to s²³ (no table): builds LOG2_TABLE once. Returns the high part, the low\n * part in LOW_PART[0]; relative error below 2^-56.\n */\nfunction log2SeriesDoubleDouble(x: number): number {\n let e = 0;\n if (x < MIN_NORMAL) { x *= TWO_POW_54; e = -54; }\n BITS[0] = x;\n const high = WORDS[HIGH]!;\n e += (high >>> 20) - 1023;\n let m = x * POW2[1074 - ((high >>> 20) - 1023)]!; // exact: m in [1, 2)\n if (m > SQRT2) { m *= 0.5; e += 1; }\n // s = f/(2 + f) with f = m − 1 (exact), as sHi + sLo: 2 + f = dh + dl exactly (FastTwoSum), then the residual\n // f − sHi·(dh + dl) with sHi·dh = p + pe exactly (TwoProduct).\n const f = m - 1, dh = 2 + f, dl = f - (dh - 2), sHi = f / dh, p = sHi * dh;\n let c = SPLITTER * sHi;\n const ah = c - (c - sHi), al = sHi - ah;\n c = SPLITTER * dh;\n const bh = c - (c - dh), bl = dh - bh, pe = ((ah * bh - p) + ah * bl + al * bh) + al * bl;\n const sLo = (((f - p) - pe) - sHi * dl) / dh;\n const z = sHi * sHi;\n const tail = sHi * z * (0.6666666666666666 + z * (0.4 + z * (0.2857142857142857 + z * (0.2222222222222222 + z * (0.18181818181818182 + z * (0.15384615384615385 +\n z * (0.13333333333333333 + z * (0.11764705882352941 + z * (0.10526315789473684 + z * (0.09523809523809523 + z * 0.08695652173913043))))))))));\n // ln m = 2sHi + (2sLo + tail) = lh + ll (FastTwoSum); times log2 e = LOG2E_HI + LOG2E_LO (TwoProduct of the high parts); plus e (TwoSum).\n const a1 = 2 * sHi, b1 = 2 * sLo + tail, lh = a1 + b1, ll = b1 - (lh - a1), q = lh * LOG2E_HI;\n c = SPLITTER * lh;\n const ch = c - (c - lh), cl = lh - ch, qe = ((ch * LOG2E_HI_H - q) + ch * LOG2E_HI_L + cl * LOG2E_HI_H) + cl * LOG2E_HI_L;\n const pl = qe + (lh * LOG2E_LO + ll * LOG2E_HI);\n const t = e + q, tb = t - e, te = (e - (t - tb)) + (q - tb), b2 = te + pl, hi = t + b2;\n LOW_PART[0] = b2 - (hi - t);\n return hi;\n}\n/** log2(k/128) for k = 90 … 182 (the table's range of k = round(128·m), m in [√½, √2]) as double-doubles. */\nconst LOG2_TABLE_LO = /* @__PURE__ */ new Float64Array(183);\nconst LOG2_TABLE_HI = /* @__PURE__ */ ((): Float64Array => {\n const table = new Float64Array(183);\n for (let k = 90; k <= 182; k++) { table[k] = log2SeriesDoubleDouble(k / 128); LOG2_TABLE_LO[k] = LOW_PART[0]!; }\n return table;\n})();\n/**\n * log2 x as a double-double for finite x > 0: returns the high part, the low part in LOW_PART[0]. x = m·2^e with m in\n * [√½, √2]; m = F·(1 + f/F) with F = k/128, k = round(128·m), so log2 m = log2 F (table) + 2·atanh(s)·log2 e with\n * s = f/(m + F), |s| < 2^-8.4, by its series to s⁷ (truncation below 2^-70 relative). Relative error below 2^-56.\n */\nfunction log2DoubleDouble(x: number): number {\n let e = 0;\n if (x < MIN_NORMAL) { x *= TWO_POW_54; e = -54; }\n BITS[0] = x;\n const high = WORDS[HIGH]!;\n e += (high >>> 20) - 1023;\n let m = x * POW2[1074 - ((high >>> 20) - 1023)]!; // exact: m in [1, 2)\n if (m > SQRT2) { m *= 0.5; e += 1; }\n // F = k/128 (exact) and f = m − F (exact, F/2 ≤ m ≤ 2F); m + F = dh + dl exactly (TwoSum); s = f/(dh + dl) as sHi + sLo\n // from the residual f − sHi·(dh + dl), with sHi·dh = p + pe exactly (TwoProduct).\n const k = Math.round(m * 128), F = k / 128, f = m - F, dh = m + F, db = dh - m, dl = (m - (dh - db)) + (F - db);\n const sHi = f / dh, p = sHi * dh;\n let c = SPLITTER * sHi;\n const ah = c - (c - sHi), al = sHi - ah;\n c = SPLITTER * dh;\n const bh = c - (c - dh), bl = dh - bh, pe = ((ah * bh - p) + ah * bl + al * bh) + al * bl;\n const sLo = (((f - p) - pe) - sHi * dl) / dh, z = sHi * sHi;\n const tail = sHi * z * (0.6666666666666666 + z * (0.4 + z * 0.2857142857142857));\n // ln(m/F) = 2sHi + (2sLo + tail) = lh + ll (FastTwoSum); times log2 e = LOG2E_HI + LOG2E_LO (TwoProduct of the high\n // parts); plus log2 F (TwoSum with the table's high part), then plus e (TwoSum).\n const a1 = 2 * sHi, b1 = 2 * sLo + tail, lh = a1 + b1, ll = b1 - (lh - a1), q = lh * LOG2E_HI;\n c = SPLITTER * lh;\n const ch = c - (c - lh), cl = lh - ch, qe = ((ch * LOG2E_HI_H - q) + ch * LOG2E_HI_L + cl * LOG2E_HI_H) + cl * LOG2E_HI_L;\n const pl = qe + (lh * LOG2E_LO + ll * LOG2E_HI), th = LOG2_TABLE_HI[k]!;\n const t = th + q, tb = t - th, low = ((th - (t - tb)) + (q - tb)) + (pl + LOG2_TABLE_LO[k]!);\n const u = e + t, ub = u - e, b2 = ((e - (u - ub)) + (t - ub)) + low, hi = u + b2;\n LOW_PART[0] = b2 - (hi - u);\n return hi;\n}\n/** 2^(th + tl) for a double-double exponent; within 1 ulp (plus the error the exponent carries). */\nfunction exp2DoubleDouble(th: number, tl: number): number {\n if (th !== th) return NaN;\n if (th > 1024) return Infinity;\n if (th < -1080) return 0;\n // th = n + r exactly (|r| ≤ ½); w = r·ln 2 = wh + wl (TwoProduct with LN2_HI, plus r·LN2_LO).\n const n = Math.round(th), r = (th - n) + tl, wh = r * LN2_HI, c = SPLITTER * r, ah = c - (c - r), al = r - ah;\n const wl = (((ah * LN2_HI_H - wh) + ah * LN2_HI_L + al * LN2_HI_H) + al * LN2_HI_L) + r * LN2_LO;\n const q = 0.5 + wh * (0.16666666666666666 + wh * (0.041666666666666664 + wh * (0.008333333333333333 + wh * (0.001388888888888889 + wh * (0.0001984126984126984 +\n wh * (2.48015873015873e-05 + wh * (2.7557319223985893e-06 + wh * (2.755731922398589e-07 + wh * (2.505210838544172e-08 + wh * (2.08767569878681e-09 +\n wh * (1.6059043836821613e-10 + wh * 1.1470745597729725e-11)))))))))));\n return scaleByPowerOfTwo(1 + (wh + (wl + wh * wh * q)), n);\n}\n\n/** log2 x, bit-identical in every JavaScript engine (within 1 ulp). 0 → −∞; negative or NaN → NaN; +∞ → +∞. */\nexport function portableLog2(x: number): number {\n if (!(x > 0)) return x === 0 ? -Infinity : NaN;\n if (x === Infinity) return Infinity;\n const h = log2DoubleDouble(x);\n return h + LOW_PART[0]!;\n}\n/** ln(k/128) for k = 90 … 182 as double-doubles (log2(k/128)·ln 2, TwoProduct with LN2_HI plus the small products). */\nconst LN_TABLE_LO = /* @__PURE__ */ new Float64Array(183);\nconst LN_TABLE_HI = /* @__PURE__ */ ((): Float64Array => {\n const table = new Float64Array(183);\n for (let k = 90; k <= 182; k++) {\n const h = LOG2_TABLE_HI[k]!, l = LOG2_TABLE_LO[k]!, p = h * LN2_HI, c = SPLITTER * h, ah = c - (c - h), al = h - ah;\n const pe = ((ah * LN2_HI_H - p) + ah * LN2_HI_L + al * LN2_HI_H) + al * LN2_HI_L, lo = pe + (h * LN2_LO + l * LN2_HI), hi = p + lo;\n table[k] = hi; LN_TABLE_LO[k] = lo - (hi - p);\n }\n return table;\n})();\n/** ln 2 = LN2_E_HI + LN2_E_LO with the low 32 bits of LN2_E_HI zero, so e·LN2_E_HI is exact for every exponent e here. */\nconst LN2_E_HI = /* @__PURE__ */ ((): number => { BITS[0] = LN2_HI; WORDS[LOW] = 0; return BITS[0]!; })(), LN2_E_LO = (LN2_HI - LN2_E_HI) + LN2_LO;\n/**\n * Natural logarithm, bit-identical in every JavaScript engine (within 1 ulp). 0 → −∞; negative or NaN → NaN; +∞ → +∞.\n * x = m·2^e, m in [√½, √2]; ln x = e·ln 2 + ln F (table, F = k/128, k = round(128·m)) + 2·atanh(s), s = (m − F)/(m + F),\n * with s as a double-double and the three terms added with TwoSum.\n */\nexport function portableLog(x: number): number {\n if (!(x > 0)) return x === 0 ? -Infinity : NaN;\n if (x === Infinity) return Infinity;\n let e = 0;\n if (x < MIN_NORMAL) { x *= TWO_POW_54; e = -54; }\n BITS[0] = x;\n const high = WORDS[HIGH]!;\n e += (high >>> 20) - 1023;\n let m = x * POW2[1074 - ((high >>> 20) - 1023)]!; // exact: m in [1, 2)\n if (m > SQRT2) { m *= 0.5; e += 1; }\n const k = Math.round(m * 128), F = k / 128, f = m - F, dh = m + F, db = dh - m, dl = (m - (dh - db)) + (F - db);\n const sHi = f / dh, p = sHi * dh;\n let c = SPLITTER * sHi;\n const ah = c - (c - sHi), al = sHi - ah;\n c = SPLITTER * dh;\n const bh = c - (c - dh), bl = dh - bh, pe = ((ah * bh - p) + ah * bl + al * bh) + al * bl;\n const sLo = (((f - p) - pe) - sHi * dl) / dh, z = sHi * sHi;\n const tail = sHi * z * (0.6666666666666666 + z * (0.4 + z * 0.2857142857142857));\n // (e·LN2_E_HI + ln F) + 2sHi with TwoSum errors, then the low parts.\n const A = e * LN2_E_HI, B = LN_TABLE_HI[k]!, t = A + B, tb = t - A, te = (A - (t - tb)) + (B - tb);\n const a2 = 2 * sHi, u = t + a2, ub = u - t, ue = (t - (u - ub)) + (a2 - ub);\n return u + ((te + ue) + ((e * LN2_E_LO + LN_TABLE_LO[k]!) + (2 * sLo + tail)));\n}\n/** 2^x, bit-identical in every JavaScript engine (within 1 ulp). */\nexport function portableExp2(x: number): number { return exp2DoubleDouble(x, 0); }\n/** e^x, bit-identical in every JavaScript engine (within 1 ulp). */\nexport function portableExp(x: number): number {\n if (x !== x) return NaN;\n if (x > 710) return Infinity;\n if (x < -746) return 0;\n // x·log2 e = th + tl: x·LOG2E_HI = th + te exactly (TwoProduct), plus x·LOG2E_LO.\n const th = x * LOG2E_HI, c = SPLITTER * x, ah = c - (c - x), al = x - ah;\n const te = ((ah * LOG2E_HI_H - th) + ah * LOG2E_HI_L + al * LOG2E_HI_H) + al * LOG2E_HI_L;\n return exp2DoubleDouble(th, te + x * LOG2E_LO);\n}\n/**\n * e^x − 1, bit-identical in every JavaScript engine (within 2 ulps): the Taylor series to degree 20 for |x| < 1\n * (truncation below 2^-60 relative), else portableExp(x) − 1.\n */\nexport function portableExpm1(x: number): number {\n if (x !== x) return NaN;\n if (x === 0) return x;\n if (!(x > -1 && x < 1)) return portableExp(x) - 1;\n return x + x * x * (0.5 + x * (0.16666666666666666 + x * (0.041666666666666664 + x * (0.008333333333333333 + x * (0.001388888888888889 + x * (0.0001984126984126984 +\n x * (2.48015873015873e-05 + x * (2.7557319223985893e-06 + x * (2.755731922398589e-07 + x * (2.505210838544172e-08 + x * (2.08767569878681e-09 +\n x * (1.6059043836821613e-10 + x * (1.1470745597729725e-11 + x * (7.647163731819816e-13 + x * (4.779477332387385e-14 + x * (2.8114572543455206e-15 +\n x * (1.5619206968586225e-16 + x * (8.22063524662433e-18 + x * 4.110317623312165e-19))))))))))))))))));\n}\n/**\n * x^y for x ≥ 0 and finite y, bit-identical in every JavaScript engine (within 1 ulp for |y| ≤ 4). x = 0 gives 0 for\n * y > 0, 1 for y = 0 and +∞ for y < 0; negative x or a non-finite argument gives NaN (the callers never pass them).\n */\nexport function portablePow(x: number, y: number): number {\n if (!(x >= 0) || !Number.isFinite(x) || !Number.isFinite(y)) return NaN;\n if (y === 0 || x === 1) return 1;\n if (x === 0) return y > 0 ? 0 : Infinity;\n // y·(lh + ll): lh·y = p + pe exactly (TwoProduct), then FastTwoSum(p, pe + ll·y).\n const lh = log2DoubleDouble(x), ll = LOW_PART[0]!, p = lh * y;\n let c = SPLITTER * lh;\n const ah = c - (c - lh), al = lh - ah;\n c = SPLITTER * y;\n const bh = c - (c - y), bl = y - bh, pe = ((ah * bh - p) + ah * bl + al * bh) + al * bl;\n const b = pe + ll * y, th = p + b;\n return exp2DoubleDouble(th, b - (th - p));\n}\n/** ∛(2^r) for r = 0, 1, 2 (only scale the cube root's starting value, so their last bits do not matter). */\nconst CBRT_POWERS_OF_TWO = [1, 1.2599210498948732, 1.5874010519681994];\n/**\n * Cube root, bit-identical in every JavaScript engine (within 1 ulp; exact for ±0, ±∞ and cubes of powers of two).\n * |x| = m·2^(3q + r) with m in [1, 2) and r in {0, 1, 2}, w = m·2^r: a cubic fit to ∛m (within 1.7·10⁻⁴) times ∛(2^r),\n * one Halley step y ← y(y³ + 2w)/(2y³ + w) (cubic convergence: below 10⁻¹¹), then one Newton step y + (w − y³)/(3y²)\n * with w − y³ formed exactly (TwoProduct), which leaves only the final rounding and errors near 10⁻²².\n */\nexport function portableCbrt(x: number): number {\n if (x === 0 || x !== x || !Number.isFinite(x)) return x;\n let a = x < 0 ? -x : x, shift = 0;\n if (a < MIN_NORMAL) { a *= TWO_POW_54; shift = -18; }\n BITS[0] = a;\n const high = WORDS[HIGH]!, e = (high >>> 20) - 1023, q = Math.floor(e / 3), r = e - 3 * q;\n const m = a * POW2[1074 - e]!, w = m * CBRT_SCALE[r]!; // exact: m in [1, 2)\n let y = (0.5561432746078446 + m * (0.5806821751356804 + m * (-0.15894786280039686 + m * 0.022291567104952514))) * CBRT_POWERS_OF_TWO[r]!;\n const y3 = y * y * y;\n y = y * (y3 + 2 * w) / (2 * y3 + w);\n // y² = p + pe exactly; y³ = p·y + pe·y = t + te (TwoProduct of p and y, plus pe·y); w − y³ = (w − t) − te.\n const p = y * y;\n let c = SPLITTER * y;\n const yh = c - (c - y), yl = y - yh, pe = ((yh * yh - p) + yh * yl + yl * yh) + yl * yl, t = p * y;\n c = SPLITTER * p;\n const ph = c - (c - p), pll = p - ph, te = (((ph * yh - t) + ph * yl + pll * yh) + pll * yl) + pe * y;\n const root = scaleByPowerOfTwo(y + ((w - t) - te) / (3 * p), q + shift);\n return x < 0 ? -root : root;\n}\n/** 2^r for r = 0, 1, 2. */\nconst CBRT_SCALE = [1, 2, 4];\n/** cos(2πr) and sin(2πr) for |r| ≤ ⅛ (Taylor series in z = r²). */\nfunction cosTwoPiReduced(r: number): number {\n const z = r * r;\n return 1 + z * (-19.739208802178716 + z * (64.9393940226683 + z * (-85.45681720669373 + z * (60.24464137187666 + z * (-26.4262567833744 + z * (7.903536371318469 +\n z * (-1.714390711088672 + z * (0.28200596845579123 + z * -0.03638284114254567))))))));\n}\nfunction sinTwoPiReduced(r: number): number {\n const z = r * r;\n return r * (6.283185307179586 + z * (-41.34170224039976 + z * (81.60524927607506 + z * (-76.70585975306139 + z * (42.058693944897655 + z * (-15.09464257682299 +\n z * (3.819952584848282 + z * (-0.7181223017785006 + z * (0.10422916220813984 + z * -0.012031585942120627)))))))));\n}\n/** cos(2πu) for finite u (u in turns), bit-identical in every JavaScript engine (within 2 ulps). */\nexport function portableCosTwoPi(u: number): number {\n if (!Number.isFinite(u)) return NaN;\n const t = 4 * u, q = Math.round(t), r = (t - q) / 4, quadrant = ((q % 4) + 4) % 4;\n return quadrant === 0 ? cosTwoPiReduced(r) : quadrant === 1 ? -sinTwoPiReduced(r) : quadrant === 2 ? -cosTwoPiReduced(r) : sinTwoPiReduced(r);\n}\n/** sin(2πu) for finite u (u in turns), bit-identical in every JavaScript engine (within 2 ulps). */\nexport function portableSinTwoPi(u: number): number {\n if (!Number.isFinite(u)) return NaN;\n const t = 4 * u, q = Math.round(t), r = (t - q) / 4, quadrant = ((q % 4) + 4) % 4;\n return quadrant === 0 ? sinTwoPiReduced(r) : quadrant === 1 ? cosTwoPiReduced(r) : quadrant === 2 ? -sinTwoPiReduced(r) : -cosTwoPiReduced(r);\n}\n"]}
|
package/dist/core/version.d.ts
CHANGED
package/dist/core/version.js
CHANGED
package/dist/core/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/core/version.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,OAAgB,CAAC","sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Version of the engine release. Since 1.0.1 it equals the npm package version.\n *\n * New captures and plans record this version as their creator. Archived records keep the\n * version they were made with. Proof-of-concept (POC), schema and model contracts have their\n * own versions. Release checks confirm it matches package.json and the packed package.\n * @see docs/RELEASE_1_0_1.md\n */\nexport const ENGINE_API_VERSION = \"2.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/core/version.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,OAAgB,CAAC","sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Version of the engine release. Since 1.0.1 it equals the npm package version.\n *\n * New captures and plans record this version as their creator. Archived records keep the\n * version they were made with. Proof-of-concept (POC), schema and model contracts have their\n * own versions. Release checks confirm it matches package.json and the packed package.\n * @see docs/RELEASE_1_0_1.md\n */\nexport const ENGINE_API_VERSION = \"2.6.0\" as const;\n"]}
|
|
@@ -361,6 +361,15 @@ export declare function resolveChartScene(input: {
|
|
|
361
361
|
scene: ChartScene;
|
|
362
362
|
aspect: number;
|
|
363
363
|
}): ResolvedChartScene;
|
|
364
|
+
/**
|
|
365
|
+
* Internal (not exported from the package): {@link resolveChartScene} with the step wedge's geometric levels computed
|
|
366
|
+
* with the portable power (`portablePow`, within 1 ulp) instead of `**`, whose last bit differs between JavaScript
|
|
367
|
+
* engines. Every other value, the geometry and the material order are the same. The display view uses its materials.
|
|
368
|
+
*/
|
|
369
|
+
export declare function resolvePortableChartScene(input: {
|
|
370
|
+
scene: ChartScene;
|
|
371
|
+
aspect: number;
|
|
372
|
+
}): ResolvedChartScene;
|
|
364
373
|
/** An axis-aligned rectangle in chart frame units: u0 ≤ u ≤ u1, v0 ≤ v ≤ v1. */
|
|
365
374
|
export interface ChartRectangle {
|
|
366
375
|
u0: number;
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
* levels, like the grey ramp: the step (below 0.1 % of the range) is far below sensor noise.
|
|
24
24
|
* @see docs/QUICK_START.md for the chart catalogue and their analytic definitions.
|
|
25
25
|
*/
|
|
26
|
+
import { portablePow } from "../core/portable-math.js";
|
|
26
27
|
import { InvalidConfigurationError } from "../core/configuration-error.js";
|
|
27
28
|
import { prepareColorimetricSpectrum } from "../color/color-matching-functions.js";
|
|
28
29
|
import { requireInputObject, requireInputKeys } from "../core/record-validation.js";
|
|
@@ -124,6 +125,15 @@ export function resolveChartScene(input) {
|
|
|
124
125
|
throw new InvalidConfigurationError("Chart aspect must be positive.");
|
|
125
126
|
return resolveScene(scene, aspect, { pictureHeight: 2 * aspect, nested: false });
|
|
126
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Internal (not exported from the package): {@link resolveChartScene} with the step wedge's geometric levels computed
|
|
130
|
+
* with the portable power (`portablePow`, within 1 ulp) instead of `**`, whose last bit differs between JavaScript
|
|
131
|
+
* engines. Every other value, the geometry and the material order are the same. The display view uses its materials.
|
|
132
|
+
*/
|
|
133
|
+
export function resolvePortableChartScene(input) {
|
|
134
|
+
requireInputObject(input, "resolveChartScene input");
|
|
135
|
+
return resolveScene(input.scene, input.aspect, { pictureHeight: 2 * input.aspect, nested: false, pow: portablePow });
|
|
136
|
+
}
|
|
127
137
|
function resolveScene(scene, aspect, context) {
|
|
128
138
|
requireInputObject(scene, "chart scene");
|
|
129
139
|
const preset = scene.preset;
|
|
@@ -209,7 +219,7 @@ function resolveScene(scene, aspect, context) {
|
|
|
209
219
|
throw new InvalidConfigurationError("spacing must be equal-density or linear.");
|
|
210
220
|
if (!(hi > lo) || (spacing === "equal-density" && lo <= 0))
|
|
211
221
|
throw new InvalidConfigurationError("Step wedge needs 0 < minimum < maximum reflectance.");
|
|
212
|
-
const values =
|
|
222
|
+
const values = stepWedgeReflectances(steps, lo, hi, spacing, context.pow);
|
|
213
223
|
return done({ steps, minimumReflectance: lo, maximumReflectance: hi, spacing, stepReflectances: values }, values.map((reflectanceValue) => ({ kind: "neutral", reflectance: reflectanceValue })), (u) => Math.min(steps - 1, Math.max(0, Math.floor((u + 1) / 2 * steps))));
|
|
214
224
|
}
|
|
215
225
|
case "grey-ramp": {
|
|
@@ -390,7 +400,7 @@ function resolveScene(scene, aspect, context) {
|
|
|
390
400
|
const list = record.elements;
|
|
391
401
|
if (!Array.isArray(list) || list.length < 1 || list.length > 256)
|
|
392
402
|
throw new InvalidConfigurationError("elements must list 1 to 256 chart elements.");
|
|
393
|
-
const nested = { pictureHeight: context.pictureHeight, nested: true };
|
|
403
|
+
const nested = { pictureHeight: context.pictureHeight, nested: true, ...(context.pow ? { pow: context.pow } : {}) };
|
|
394
404
|
const background = resolveScene(get("background"), aspect, nested);
|
|
395
405
|
const materials = [...background.materials], inputs = [...chartMaterialInputs(background)];
|
|
396
406
|
for (const key of background.defaultedParameters)
|
|
@@ -410,7 +420,7 @@ function resolveScene(scene, aspect, context) {
|
|
|
410
420
|
if (e.mask === undefined)
|
|
411
421
|
defaulted.push("elements." + index + ".placement.mask");
|
|
412
422
|
// The element's own frame: u = ±1 across its width; frequencies keep the composite's picture height.
|
|
413
|
-
const chart = resolveScene(e.scene, height / width, { pictureHeight: context.pictureHeight * 2 / width, nested: true });
|
|
423
|
+
const chart = resolveScene(e.scene, height / width, { pictureHeight: context.pictureHeight * 2 / width, nested: true, ...(context.pow ? { pow: context.pow } : {}) });
|
|
414
424
|
for (const key of chart.defaultedParameters)
|
|
415
425
|
defaulted.push("elements." + index + ".parameters." + key);
|
|
416
426
|
const offset = materials.length;
|
|
@@ -636,11 +646,14 @@ export function calculateStepWedgeReflectances(input) {
|
|
|
636
646
|
throw new InvalidConfigurationError("spacing must be equal-density or linear.");
|
|
637
647
|
if (!(hi > lo) || (input.spacing === "equal-density" && lo <= 0))
|
|
638
648
|
throw new InvalidConfigurationError("Step wedge needs 0 < minimum < maximum reflectance.");
|
|
649
|
+
return stepWedgeReflectances(steps, lo, hi, input.spacing, undefined);
|
|
650
|
+
}
|
|
651
|
+
function stepWedgeReflectances(steps, lo, hi, spacing, pow) {
|
|
639
652
|
return Array.from({ length: steps }, (_, k) => {
|
|
640
653
|
if (k === steps - 1)
|
|
641
654
|
return hi;
|
|
642
655
|
const t = k / (steps - 1);
|
|
643
|
-
return
|
|
656
|
+
return spacing === "linear" ? lo + (hi - lo) * t : lo * (pow ? pow(hi / lo, t) : (hi / lo) ** t);
|
|
644
657
|
});
|
|
645
658
|
}
|
|
646
659
|
/** Centres (frame units) of a point grid: one disk centred in each of columns × rows equal cells, row-major from the top-left. */
|