float ParallelResistance(float R1, float R2) { return 1.0 / ( (1.0 / R1) + (1.0 / R2) ); }
Suppose R2
is 0. Then the expression 1.0 / ((1.0 / R1) + (1.0 / 0.0))
evaluates to
, or 0, as expected of a short circuit. Similarly, if R2
is infinite, an open circuit, the result is R1
. On pre-IEEE platforms, this program would be sprinkled with tests to avoid division by zero and with magic numbers such as 1.0E30
to represent (essentially) infinite resistance.