A small note about adding +0.0
to an expression which you say should have essentially no impact. There is no impact most of the time but there are a few exceptions that are worth being aware of:
- If the expression has the value
-0.0
(yes IEEE-754 has a plus and minus zero) then adding+0.0
to it changes the sign of the expression to positive. This is unlikely to cause a problem because most people check the sign by doingx >= 0
which returns true for-0.0
. The problem is observable if you use thesignbit()
function to check the sign. - If the expression is a signalling NaN adding
+0.0
to it will turn it into a quiet NaN and raise an invalid operation exception. This is very unlikely to ever be a problem though as I’m not sure GLSL has any support for IEEE-754 exceptions or even cares about the distinction between signalling and quiet NaN.