Maths & numbers

Quadratic irrational continued fraction period calculator

An irrational expression(a+b√D)/c has an eventually periodic simple continued fraction when its coefficients are integers and D is positive nonsquare.

Your numbers

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

An irrational expression(a+b√D)/c has an eventually periodic simple continued fraction when its coefficients are integers and D is positive nonsquare. The page finds the finite preperiod and the repeating block,then uses that block to construct exact rational convergents beyond the first observed cycle.

THE FORMULAx_(k+1)=1/(x_k−floor(x_k));p_k=a_k p_(k−1)+p_(k−2).

A worked example

√2 has preperiod[1],period[2],and convergents1/1,3/2,7/5,17/12,41/29.

Good to know

Integer |a|,|c|≤10,000,nonzero |b|≤100,nonsquare D2–10,000,nonzero c. Exact surd comparisons and10,000-state cap;20 convergents displayed.

Quadratic irrationals eventually repeat

An irrational expression(a+b√D)/c has an eventually periodic simple continued fraction when its coefficients are integers and D is positive nonsquare. The page finds the finite preperiod and the repeating block,then uses that block to construct exact rational convergents beyond the first observed cycle.

A rational continued fraction terminates instead. Neither behavior should be guessed by looking for repeated decimal digits or repeated approximate remainders. The implementation detects repetition of an exact normalized quadratic-surd state,which is the mathematical object that determines the next partial quotient.

Exact periodic continued fractions of quadratic surds13/27/517/1241/29√2 = [1; 2,2,2,…]Exact convergents;period [2]
Scroll across to see the full diagram.
√2 has preperiod[1],period[2],and convergents1/1,3/2,7/5,17/12,41/29.

Compare this with the Rational continued fraction calculator. Compute the preperiod,period and convergents of (a+b√D)/c exactly; rational Euclidean expansions terminate instead.

Keep the radicand genuinely irrational

Enter integer a,b,c and a positive nonsquare D,with b and c nonzero. Negative numerators or denominators are allowed and normalized consistently. If D were a square,or b were zero,the expression would be rational and should be handled by the finite rational continued-fraction calculator.

D need not be squarefree for this representation to work;the exact radical comparisons still use the stated expression. Bounds on coefficients and a ten-thousand-state cap keep the calculation finite in the interface. Exceeding the cap is an unresolved period search,not evidence of nonperiodicity.

A floor requires more than rounded evaluation

At each step,the partial quotient is the mathematical floor of the current surd. A decimal approximation supplies an initial candidate,but exact comparisons adjust it. The sign of u+v√D is decided using signs and integer-square comparisons when the two terms oppose one another.

This matters near an integer boundary,where subtraction can cancel many leading decimal digits. Accepting the rounded floor could change every subsequent quotient and create a false period. The proof of each floor comes from the exact comparison,not from the numerical seed used to locate it quickly.

Normalize and remember the complete quotient

After subtracting the floor,the algorithm takes the reciprocal and rationalizes it back into a quadratic-surd state. A common gcd is removed and the denominator sign is normalized. Equivalent states then have the same stored key,even when a raw formula would leave redundant common factors.

When a previously seen state returns,all subsequent steps repeat deterministically. The first occurrence of that state marks the start of the period. Any earlier partial quotients form the preperiod;they are not automatically included in the repeating block merely because they precede its first complete traversal.

Square root two as a worked example

For a=0,b=1,D=2,c=1,the expansion is[1;2,2,2,…]. The preperiod is the single quotient one and the period has length one,containing two. The first convergents are1/1,3/2,7/5,17/12 and41/29.

Their values alternate around√2. Successive numerators and denominators obey p_n=a_n p_(n−1)+p_(n−2) and the analogous denominator recurrence. They are stored as exact integers,so a later convergent can have many digits without becoming a rounded floating-point fraction.

Period data and displayed convergents are separate

The complete repeating block is returned when the state search closes. The interface then displays twenty convergents,cycling through that proven block as necessary. Twenty displayed rows therefore does not mean the period length is twenty or that only twenty partial quotients exist.

A long period may contain more quotients than the convergent table displays. Conversely,a short period can generate indefinitely many distinct convergents. Preserve the preperiod/period split when transferring the expansion to another program;concatenating them into one repeating list changes the represented number.

Use exact structure for later calculations

The expansion can support Diophantine approximation or a later Pell-type analysis,but this page does not claim to solve every norm equation associated with the field. A fundamental unit or a generalized Pell solution needs its own equation and sign conventions beyond merely reading a period length.

The result is also not a decimal error certificate for a truncated convergent. Standard continued-fraction inequalities can provide such bounds using consecutive denominators. Here the main certificates are exact floors,exact state repetition and exact convergent recurrences,which should be retained with the original surd.

A few questions, answered

Must D be squarefree?

No. It must be positive nonsquare;the represented real number remains quadratic irrational.

How is the period recognized?

An exact normalized complete-quotient state repeats;matching rounded decimal values is not used as proof.

Is the preperiod repeated too?

No. Only the separately returned period block repeats indefinitely.

Are the twenty convergents the entire expansion?

No. The infinite expansion continues using the proven repeating block.

Find your calculator

Start typing to explore the library.