function result = polaritySelect(polarity, whenPositive, whenNegative)
%POLARITYSELECT selects whenPositive if polarity is +1, whenNegative if
%polarity is -1.  

%   Copyright 2011-2013 The MathWorks, Inc.
%#codegen

  sum  = whenPositive + whenNegative;
  diff = whenPositive - whenNegative;
  result = (sum + diff .* polarity) / 2;
end

