Rational Approximation & Denominator Budget Calculator

Enter a decimal or exact fraction and a maximum denominator. Compare the nearest fractions on each side and see when they tie. Set an absolute tolerance to find the smallest denominator that meets it, and inspect exact results at selected denominator caps.

Bounded fraction approximation

Choose a fraction within a denominator budget

Compare exact fractions on each side of your target and find the first denominator that meets your tolerance.

Best permitted fraction
355/113
Closest overall · Absolute error 2.66764189e-7
First denominator meeting tolerance
113
Tolerance 1e-6
Edit target and denominator
Approximation direction

Error across denominator caps

Dots mark errors at the plotted denominator caps. Smaller errors appear lower.

Closest overall error at 36 denominator capsAbsolute errors for discrete denominator caps. Lower dots have smaller error. Exact matches sit at the bottom.
Cap 1Cap 1,000
Positive-error scale 1e-7 to 1e0 (log). The dashed line is your tolerance. Exact matches sit on the zero line. The cap axis is logarithmic.

At denominator cap 1,000

Selected fraction
355/113
Absolute error
2.66764189e-7
Closest at or below
2818/897
Lower signed error
-9.59896326e-6
Closest at or above
355/113
Upper signed error
+2.66764189e-7

Exact directional results

Exact target 7853981633974483/2500000000000000

Closest overall

Candidate
355/113
Signed error
+2.66764189e-7
Exact absolute error
75360883421/282500000000000000
First denominator meeting tolerance
113
First qualifying fraction
355/113

At or below

Candidate
2818/897
Signed error
-9.59896326e-6
Exact absolute error
21525675111251/2242500000000000000
First denominator meeting tolerance
No qualifying denominator

At or above

Candidate
355/113
Signed error
+2.66764189e-7
Exact absolute error
75360883421/282500000000000000
First denominator meeting tolerance
113
First qualifying fraction
355/113
Download denominator comparison CSV
Show selectable CSV

How to use this calculator

  1. Enter the reference value as a decimal or exact fraction.
  2. Set the largest allowed reduced denominator and choose closest overall, at or below, or at or above.
  3. Enter an optional maximum absolute error to find the first qualifying denominator within your budget.
  4. Select a plotted denominator cap and compare both directions and any ties.
  5. Export the exact target, candidates, tolerance witnesses and sampled caps.

The Formula

The mathematical logic powering this calculation is:

The target is the exact rational represented by your entered decimal or fraction. A positive denominator is required for fraction entries. A denominator cap N allows any reduced denominator from 1 through N. If the target’s reduced denominator fits, its exact form serves as both directional choices.

Otherwise bracket the target between exact adjacent fractions. Begin at the mathematical floor and the next integer, even for negative targets. Adjacent Stern–Brocot fractions a/b and c/d satisfy bc − ad = 1. Their mediant (a + c)/(b + d) has the smallest denominator available strictly between them. Move the appropriate boundary toward the target while the new denominator fits the cap. The solver takes several consecutive steps at once using integer quotients when that stays within the target and cap. When the mediant denominator exceeds N, the bounds are the closest admissible fractions on their respective sides.

Signed error equals candidate minus target. At or below and At or above include exact equality. The closest overall choice has the smallest absolute error from the target. If both distinct candidates have the same error, the result retains both. Increasing a cap can preserve or improve the best error for each direction.

An optional tolerance is a maximum absolute difference, with equality included. The solver finds the smallest denominator cap whose best permitted error meets it. This returns the first witness within the entered budget. A zero tolerance requires an exact fraction. Unmet tolerance at the maximum cap leaves the closest available fractions visible.

The plot uses exact error values at the displayed caps. Large budgets use selected checkpoints, including important boundaries, and a logarithmic denominator axis. Positive errors use a logarithmic display. Exact zero is shown separately. Select a plotted cap to inspect its recorded choices and signed errors. Between displayed caps the calculation can change at an unplotted denominator.

Enter values from −1 trillion to 1 trillion, with up to 24 fractional decimal digits or exact fractions with up to 38 digits in each term. The denominator cap accepts 1 through 1,000,000. The optional absolute tolerance ranges from zero to 1 trillion. Boundary decisions and the CSV use exact integer arithmetic. Chart positions and decimal error labels are for reading the comparison.

Worked Example

If you input:

  • Exact entered target: 3.1415926535897932
  • Denominator cap: 1,000
  • Absolute error tolerance: 0.000001
  • Direction: Closest overall

Result:

355/113 is the closest fraction. Its error is approximately +2.66764189e-7 and denominator 113 is the first cap that meets the tolerance. The best fraction at or below the target is 2818/897. It misses the same tolerance at cap 1,000.

Frequently Asked Questions

Why might the exact decimal fraction exceed my denominator cap?

A finite decimal is an exact rational, and its reduced denominator can be large. The cap asks for a simpler fraction even when that exact representation is unavailable.

What happens when two fractions are equally close?

The closest-overall result retains both fractions. The directional results show one candidate on each side.

How does the calculator handle a negative target?

It starts at the mathematical floor and works with the same exact directional comparisons. At or below means numerically smaller or equal, which can be more negative.

Does a zero tolerance require exact equality?

Yes. A zero tolerance is reached only at a cap that allows the exact reduced denominator.

Why can a larger denominator budget return the same fraction?

The cap allows every smaller denominator. If no newly admissible fraction gives a better result in the chosen direction, the previous candidate stays optimal.

Similar Calculators