Mix Function - Increases Floating Point Amount

I looked through the code base and found the following template function:

template <class T, class T2>
T mix(const T &a, const T &b, const T2 &interp) {
  static constexpr T2 one = ((T2)1);
  return (a * (one - interp)) + (b * interp);
}

And the next comment

// You'd think instead of doing the a*(1-t) + b*t, it'd be faster
// and one less multiply to do a + (b-a)*t, right? Bad! Increases floating
// point exception occurances. Same as LERP

Can someone emphasize why this should be true?

+4
source share
1 answer

As Paul R said in the comments, the comments are probably denormal (I usually think of them as subnormal, so we will use the term), which fill the gap of the lower stream around zero in floating point arithmetic.

a b , a-b . , . , , , 100 , , . (, , , , ) .

(, , ) (, , ).

, , interp, , 1.0.

+3

All Articles