? Rationalize

Rationalize[x] takes Real numbers in x that are close to   rationals, and converts them to ... performs the conversion whenever the error made is smaller in magnitude than   dx. More…

The line below finds a rational number that is very close to the machine
number approximation of Pi.

est1 = Rationalize[N[π], 0]


Rationalize[N[π],0.0]  gives the same number as the line above.

N[π - est1, 17]


The next line gives a rational approximation of π that is remarkably
close to the actual value of π.

est = Rationalize[π, 0.]


Block[{$MaxExtraPrecision = 800},   N[π - est, 17]   ]


If you want to quickly convert a Real to a Rational and you don't care about
large integers in the numerator and denominator the next line should be used.
It's about 26 times faster than Rationalize!

SetPrecision[14.2, ∞]


Created by Mathematica  (May 16, 2004)

Back to Ted’s Tricks index page