(cls, f)
return cls(*f.as_integer_ratio())
Converts a finite float to a rational number, exactly.

        Beware that Fraction.from_float(0.3) != Fraction(3, 10).
Converts a finite float to a rational number, exactly.
Converts a finite float to a rational number exactly .
def from_float(cls, f):
        """Converts a finite float to a rational number, exactly.

        Beware that Fraction.from_float(0.3) != Fraction(3, 10).

        """
        if isinstance(f, numbers.Integral):
            return cls(f)
        elif not isinstance(f, float):
            raise TypeError("%s.from_float() only takes floats, not %r (%s)" %
                            (cls.__name__, f, type(f).__name__))
        return cls(*f.as_integer_ratio())
def from_float ( cls , f ) : if isinstance ( f , numbers . Integral ) : return cls ( f ) elif not isinstance ( f , float ) : raise TypeError ( "%s.from_float() only takes floats, not %r (%s)" % ( cls . __name__ , f , type ( f ) . __name__ ) ) return cls ( * f . as_integer_ratio ( ) )