Division in MathMix and MathCombine produces precision errors

Hi there,

I’ve discovered precision issues with division in MathMix and MathCombine. It’s currently not possible to get correct results when dividing using attributes, uniforms, or built-in attributes — only manually entered constants produce the expected values.

This appears to be related to the other issue I reported earlier regarding mod(), which was recently fixed here:

I’m attaching a detailed breakdown of the issue:

DivisionBug.tox (10.3 KB)

I’m on Windows, NVidia RTX4090, on build 31760

Best,
Darien

Hi @Darien.Brito,

thanks for reporting this, we are having a look.

cheers
Markus

1 Like

Hello @Darien.Brito

This will be fixed in the next build. The solution is the same as the fix applied to the mod() function: we now cast to doubles. I suspect that the error could be coming from a shader compiler optimization.
Instead of doing A / B, the compiler might do A * (1.0 / B) and in your example, 1.0 / 33.0 can’t be precisely represented with floats. As far as I know, there’s no way to disable those optimizations per shader for now.

1 Like

Hi @Guillaume.L and @snaut . Thanks for the fix!

It stemming perhaps from some compiler optimization does sense. I have seen this kind of floating point error or truncation before indeed, in some GLSL implementations. Tricky stuff to fix systematically, but glad a fix for this one is coming! :slight_smile:

Best,
Darien