Arithmetic with infinities

A principle of elementary electricity illustrates the utility of the values and in the number system. This function returns the resistance of two resistors wired in parallel:

      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.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker