Obtaining infinity by dividing by 0 breaks minification
jroessel opened this issue · comments
Johannes Rössel [yWorks] commented
In rewriter.fs, constant folding for numeric expressions is performed:
| FunCall(Op "/", [Float (i1,su); Float (i2,_)]) as e ->
let div = Float (i1 / i2, su)
if (Printer.exprToS e).Length <= (Printer.exprToS div).Length then e
else div
However, for 1. / 0.
this results in a division by 0 exception. Can be fixed with
@@ -158,7 +158,7 @@
| FunCall(Op "-", [Float (i1,su); Float (i2,_)]) -> Float (i1 - i2, su)
| FunCall(Op "+", [Float (i1,su); Float (i2,_)]) -> Float (i1 + i2, su)
| FunCall(Op "*", [Float (i1,su); Float (i2,_)]) -> Float (i1 * i2, su)
- | FunCall(Op "/", [Float (i1,su); Float (i2,_)]) as e ->
+ | FunCall(Op "/", [Float (i1,su); Float (i2,_)]) as e when i2 <> 0.0m ->
let div = Float (i1 / i2, su)
if (Printer.exprToS e).Length <= (Printer.exprToS div).Length then e
else div
Although I wonder whether using decimal
is actually desirable here, considering that shaders work with IEEE 754 floats. Or is that more to allow both integers and floats to pass through the same code in the minifier?
Theron Tarigo commented
Beware that leaving 1./0.
in the shader can result in a similar error in the driver shader compiler itself, at least with OpenGL.
Eldritch Conundrum commented
Fixed last year, forgot to close.