# Does Mathematica have an equivalent of Python's float.as_integer_ratio?

The Python programming language has a float.as_integer_ratio(x) function which exactly converts an IEEE 754 floating-point number into a numerator/denominator pair of integers. For example:

float.as_integer_ratio(0.1)
=> (3602879701896397, 36028797018963968)


What is the Mathematica equivalent of this function for MachinePrecision numbers?

SetPrecision[] does this:

SetPrecision[0.1, ∞]
3602879701896397/36028797018963968

• Indeed it does. Thanks! – David Zhang May 24 '15 at 4:33
• SetAccuracy appears to be equivalent. (+1) – Mr.Wizard May 24 '15 at 10:13

Not as clean as J.M.'s method but this seems to give the same result:

 0.1 ~RealDigits~ 2 ~FromDigits~ 2

3602879701896397/36028797018963968


Follow with Numerator and Denominator if needed.