Function reference · Math

continued_fraction

Returns the continued fraction of a number.

The result is (sign, whole part, [partial quotients]). A second argument limits how many partial quotients are computed.

Notation

continued_fraction(x, depth)

Write it in an expression: nerdamer('continued_fraction(415/93)'), or in the Playground.

nerdamer.continued_fraction

nerdamer.continued_fraction(x: ExpressionInput, depth: ExpressionInput): Collection

A method on the default import. Arguments can be strings, as in Notation.

Examples

415/93 = 4 + 1/(2 + 1/(6 + 1/7)).

continued_fraction(415/93)
// → (1, 4, [2, 6, 7])
Open in Playground

Stop after two partial quotients.

continued_fraction(415/93,2)
// → (1, 4, [2, 6])
Open in Playground

The sign comes first.

continued_fraction(-415/93)
// → (-1, 4, [2, 6, 7])
Open in Playground

355/113, a close approximation of pi.

continued_fraction(355/113)
// → (1, 3, [7, 16])
Open in Playground

← Back to Function reference