I understand why floating point numbers cannot be compared and know about the binary representation of the mantissa and exponent, but I am not an expert, and today I came across something that I don’t get:
Namely, let's say you have something like:
float denominator, numerator, resultone, resulttwo; resultone = numerator / denominator; float buff = 1 / denominator; resulttwo = numerator * buff;
As far as I know, different flops can give different results, and this is not unusual. But in some regional cases, these two results seem to be significantly different. To be more specific in my GLSL code calculating the Beckmann torch slope distribution for the Cook-Torrance performance model:
float a = 1 / (facetSlopeRMS * facetSlopeRMS * pow(clampedCosHalfNormal, 4)); float b = clampedCosHalfNormal * clampedCosHalfNormal - 1.0; float c = facetSlopeRMS * facetSlopeRMS * clampedCosHalfNormal * clampedCosHalfNormal; facetSlopeDistribution = a * exp(b/c);
gives very different results for
float a = (facetSlopeRMS * facetSlopeRMS * pow(clampedCosHalfNormal, 4)); facetDlopeDistribution = exp(b/c) / a;
Why? The second form of expression is problematic.
If I say, I try to add the second form of the expression to the color, I get black, although the expression should always be evaluated with a positive number. Am I getting infinity? NaN? if so, why?
user515136
source share