Repeating decimal
Algorithm for positive bases

For a rational 0 < p / q < 1 (and base b ∈ N) there is the following algorithm producing the repetend together with its length:

The first highlighted line calculates the digit z.

The subsequent line calculates the new remainder p′ of the division modulo the denominator q. As a consequence of the floor function floor we have

thus

and

Because all these remainders p are non-negative integers less than q, there can be only a finite number of them with the consequence that they must recur in the while loop. Such a recurrence is detected by the associative array occurs. The new digit z is formed in the yellow line, where p is the only non-constant. The length L of the repetend equals the number of the remainders (see also section Every rational number is either a terminating or repeating decimal).
language:response_language[Latin], oulipo:avoid_letter[a], startend:quotation