Skip to content

Commit fc81bc3

Browse files
committed
FDiv constant folding for divide-by-zero produces IEEE 754 NaN/Inf
Remove the (!= b 0.0) guard from FDiv constant folding, allowing divide-by-zero to produce correct IEEE 754 results: 0.0/0.0 → NaN, x/0.0 → ±Inf. Egglog's native f64 division follows IEEE 754 semantics, and FConst already supports NaN/Inf values in parsing and extraction. This matches the C++ FoldFPScalarDivideByZero behavior.
1 parent 529e110 commit fc81bc3

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

rust/spirv-tools-opt/src/rules/constant_folding.egg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
((union e (FConst (- a b)))))
4141
(rule ((= e (FMul (FConst a) (FConst b))))
4242
((union e (FConst (* a b)))))
43-
(rule ((= e (FDiv (FConst a) (FConst b))) (!= b 0.0))
43+
; Divide-by-zero produces IEEE 754 results: 0/0→NaN, x/0→±Inf
44+
(rule ((= e (FDiv (FConst a) (FConst b))))
4445
((union e (FConst (/ a b)))))
4546
; Use float-neg primitive (sign bit flip) instead of 0.0 - a,
4647
; because IEEE 754: 0.0 - 0.0 = +0.0, but FNeg(+0.0) must be -0.0.

0 commit comments

Comments
 (0)