The op amp is alternately an inverter or buffer, under control of the switch polarity. As a buffer, the gai
n is always 1, but as an inverter, the gain is set by the ratio of the input and feedback resistors. By adding a comparator, the function can be synchronously switched as the input polarity changes, which effectively rectifies the output. The output polarity is determined by the switch logic (normally open or normally closed) and the comparator input polarity.