Skip to content

Commit e69143a

Browse files
ahrzbclaude
authored andcommitted
fix(tests): %-by-zero NaN sign is platform libm — pin engine==oracle bit agreement, not a constant (CI)
Windows ucrt says 7ff8, Linux glibc fff8; both engines call the platform libm so they agree per-platform (the cbrt situation again). fmod's NaN is hardware-generated (0*inf under SSE) and stays fff8 everywhere — that constant keeps its pin. Spec addendum updated. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 1811d48 commit e69143a

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

docs/superpowers/specs/2026-07-26-wave3-builtin-pins.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,12 @@ noted. Nothing here is inferred from documentation.
106106
INT x%0 → NULL (no trap); DOUBLE x%0.0 → **NaN 7ff8…** (a value, NOT
107107
NULL — the fleet's decision line over-generalized from the int probes;
108108
re-measured 2026-07-26, correction appended to pins-wave3/math_tail.json.
109-
Note the NaN-sign contrast: %-by-zero is 7ff8, fmod-by-zero is fff8);
110-
mod(−7.5,2.5) = **−0.0**.
109+
NaN-sign addendum (CI-discovered): the %-by-zero NaN comes from LIBM
110+
fmod and its sign is PLATFORM-dependent — 7ff8 on Windows ucrt, fff8 on
111+
Linux glibc; both engines use the platform libm so they agree with the
112+
oracle per-platform, and the pin is bit AGREEMENT, not a constant.
113+
fmod-by-zero is hardware-generated (0·inf under SSE) and stays fff8
114+
everywhere); mod(−7.5,2.5) = **−0.0**.
111115
- `fmod`/`fdiv` are the FLOOR-division pair, always DOUBLE: fdiv =
112116
floor(x/y) (±inf on zero divisor); fmod takes the **DIVISOR's** sign
113117
(fmod(−7.5,2.5) = +0.0 where mod gives −0.0) and is computed as

tests/test_duckdb_wave3_mathtail.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,13 @@ def test_fdiv_fmod_double_edges():
204204

205205

206206
def test_computed_nan_bits_match_oracle():
207-
# repr collapses every NaN to 'nan', so pin the BITS manually: fmod's
208-
# computed NaN is fff8… (negative quiet NaN) while % by zero NULL-path
209-
# NaN stays 7ff8… — in BOTH engines.
207+
# repr collapses every NaN to 'nan', so pin the BITS manually. fmod's
208+
# NaN comes from hardware arithmetic (0*inf under SSE) and is fff8…
209+
# on every x86 platform. The %-by-zero NaN comes from LIBM fmod and
210+
# its SIGN is platform-dependent (Windows ucrt 7ff8…, Linux glibc
211+
# fff8… — CI-discovered, the cbrt situation again): both engines use
212+
# the platform libm, so the pin is ENGINE == ORACLE bit agreement,
213+
# not a constant.
210214
def bits(v: float) -> str:
211215
return format(struct.unpack("<Q", struct.pack("<d", v))[0], "016x")
212216

@@ -218,14 +222,13 @@ def bits(v: float) -> str:
218222
)
219223
(got,) = fn.infer({"__THIS__": [row(x=7.5, y=0.0)]})
220224
assert bits(got.f) == "fff8000000000000"
221-
assert bits(got.m) == "7ff8000000000000"
222225

223226
con = duckdb.connect()
224227
con.execute("CREATE TABLE __THIS__ (x DOUBLE, y DOUBLE)")
225228
con.execute("INSERT INTO __THIS__ VALUES (7.5, 0.0)")
226229
f, m = con.execute("SELECT fmod(x, y), x % y FROM __THIS__").fetchone()
227230
assert bits(f) == "fff8000000000000"
228-
assert bits(m) == "7ff8000000000000"
231+
assert bits(got.m) == bits(m), f"{bits(got.m)} vs oracle {bits(m)}"
229232

230233

231234
# ----------------------------------------------------------- nextafter:

0 commit comments

Comments
 (0)