def checkFinite(value, name='value'):
        """Check that value is a finite number.

        If it is, return it. If not, raise GraphError describing the
        problem, using name in the error message.
        """
        if math.isnan(value):
            raise GraphError('Encountered NaN %s' % (name,))
        elif math.isinf(value):
            raise GraphError('Encountered infinite %s' % (name,))
        return value
Check that value is a finite number.

        If it is, return it. If not, raise GraphError describing the
        problem, using name in the error message.