Decimal to Fraction Function - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: HP Prime Software Library (/forum-15.html) +--- Thread: Decimal to Fraction Function (/thread-2024.html) |
Decimal to Fraction Function - Namir - 08-27-2014 06:18 PM The following function takes the following parameters: 1) x - the fraction to be converted. 2) n - the number of continued fraction terms. 3) toler - the residual tolerance (to prevent divisions by small numbers). The function returns the following values: 1) The approximation for x. 2) The numerator. 4) The denominator. The approximation for x = numerator / denominator. 4) The difference between x and its approximated value. Here is the HP Prime listing: Code:
Here is an example: Code: Dec2Frac(pi,4,0.0001) Enjoy! Namir PS: Many many thanks for Joe Horn who patently pointed out the many errors in the code. I feel a bit ashamed, because I should have done a much better job posting these simple programs. My former Jesuit teachers would have commented that I "did a sloppy job!". Thanks Joe!! |