def float_to_rational(self, a): assert np.all(a > 0.0) d = 2**16 / np.fix(a+1).astype(int) # Uglier than it used to be: np.int(a + 1) n = np.fix(a * d + 1).astype(int) return n, d