<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Dec 19, 2014 at 6:02 PM, Matt Turner <span dir="ltr"><<a href="mailto:mattst88@gmail.com" target="_blank">mattst88@gmail.com</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Fri, Dec 19, 2014 at 5:04 PM, Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>> wrote:<br>
> v3: fmin and fmax technically aren't commutative or associative.  Things<br>
>     get funny when one of the arguments is a NaN.<br>
<br>
</span>I have a difficult time believing that the GLSL definitions of min()<br>
and max() intentionally have that effect.<br>
<br>
To recap, the definition of min() in GLSL is<br>
<br>
> Returns y if y < x, otherwise it returns x.<br>
<br>
and since comparisons against NaN are always false, min(x, y) where x<br>
or y is NaN will always return x, regardless of which argument is NaN.<br>
That doesn't seem like a useful behavior.<br>
<br>
Indeed the GLSL spec says<br>
<br>
> Operations and built-in functions that operate on a NaN are not required to return a NaN as the result.<br>
<br>
I think based on that text alone, min() and max() should be considered<br>
commutative and associative.<br></blockquote><div><br></div><div>As a datapoint, apparently Merek (cc'd) bumped into this at one point on some unreal game.  Perhaps he could shed some light.<br></div><div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Ian, perhaps we should clarify this with Khronos?<br>
<br>
An IEEE 754 spec draft [1] defines minNum(x, y) as "y if x<y, x if<br>
y<x, the canonicalized floating-point<br>
number if one operand is a floating-point number and the other a NaN.<br>
Otherwise it is either x<br>
or y."<br></blockquote><div><br></div><div>That seems to imply that min(x, NaN) = min(NaN, x) = x which would make it commutative and associative.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
i965's SEL instruction implements that behavior.<br>
<br>
[1] <a href="http://754r.ucbtest.org/drafts/archive/2006-10-04.pdf" target="_blank">http://754r.ucbtest.org/drafts/archive/2006-10-04.pdf</a><br>
</blockquote></div></div></div>