Skip to content

Commit ec8e295

Browse files
fuzzie360claude
andcommitted
test: Stop asserting exact equality on sqrt results
sqrtAB compared Math.sqrt(a*b) against whole numbers with deepEqual, so it failed on headless-gl with 7.000000476837158 for sqrt(49.0). That value is 1 ULP above 7.0, and GLSL ES allows sqrt up to 2 ULP of error — it is not in the correctly-rounded set with + - * /. So the driver is conforming and the assertion was asking for a guarantee gpu.js cannot make. Confirmed the arithmetic itself is fine: a*b returns exactly 49, and sqrt of a literal 49 folds to exactly 7; only the runtime sqrt carries the ULP. Compare within 2 ULP of the expected magnitude instead, which is still tight enough to catch a genuinely wrong result. macOS suite goes 12 -> 9 failures; the remaining 9 are the signed-right-shift and Infinity encoding families. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent b0dedd2 commit ec8e295

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎test/features/math-object.js‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,17 @@ function sqrtABTest(mode) {
171171
const res = f(a,b);
172172
const exp = [3, 4, 5, 6, 7, 8];
173173

174-
assert.deepEqual(Array.from(res), exp);
174+
// GLSL ES allows sqrt up to 2 ULP of error — unlike + - * / it is not
175+
// required to be correctly rounded — so exact equality is not a property
176+
// gpu.js can offer here. headless-gl returns 7.000000476837158 for
177+
// sqrt(49.0), which is 1 ULP above 7.0 and entirely conforming.
178+
Array.from(res).forEach((actual, i) => {
179+
const ulp = Math.pow(2, Math.floor(Math.log2(exp[i])) - 23);
180+
assert.ok(
181+
Math.abs(actual - exp[i]) <= 2 * ulp,
182+
`index ${i}: expected ${exp[i]} within 2 ULP, got ${actual}`
183+
);
184+
});
175185
gpu.destroy();
176186
}
177187

0 commit comments

Comments
 (0)