With this circuit, you can generate an output proportional to the absolute value of the difference between two input voltages, V1 and V2 (see the figure).
The circuit handles input signals over the voltage range of 0 to +5 V, and operates from a single 5-V power supply. Its output voltage is equal to 4.994 × |V − V2|.
The circuit uses three-fourths of an LM660, as an inverting stage (the leftmost U1), a rectifier (the middle U1), and an output stage to provide gain and level shifting.
The approximate output current is Io = | V1 − V2 |/R1; the approximate output voltage is calculated from Vo= 2.5 (1 – RF/RB) + (Io × RF).