Find Repeating Part of a Fraction
This function takes two parameters, the numerator and denominator of a fraction, and determines the repeating part of the fraction (if one exists).
The logic is simple: After removing any part of the result that is a whole number, it begins dividing the denominator into the numerator and tracking the remainder after each digit. If the remainder becomes 0, then the function is done. Otherwise, when a remainder repeats, it has found the repeating part.
Because Perl treats all numbers as floating-point numbers, the easiest way to truncate a number to its integer part is to sprintf() it into a string using the "%d" ...
Get Find the Bug A Book of Incorrect Programs now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.