(12C) Decimal to Fraction
|
08-06-2018, 08:44 PM
(This post was last modified: 08-06-2018 08:54 PM by Dieter.)
Post: #2
|
|||
|
|||
RE: (12C) Decimal to Fraction
(08-06-2018 12:33 PM)Gamo Wrote: Program to covert Decimal to Fraction. The program only seems to return a result if the calculated fraction exactly (!) matches the input. But I am not sure if I really understand how it works. But why don't you simply use the well-known continued fraction method? Here is an adaptation for the 12C and its limited command set: Code: 01 STO 0 The program stops if the fraction agrees with the (positive) input when rounded to display precision. Example: Determine a fraction that agrees with √2 in four decimals. FIX 4 2 [√x] [R/S] => 239 [X<>Y] 169 Indeed the quotient is 1,414201183. Or try pi to six decimals: FIX 6 3,141592654 [R/S] => 355 [X<>Y] 113 The well known approximation 355/113 = 3,141592920. That's 3,141593 when rounded to 6 decimals. Finally your example: what's exactly 3,1416 ? FIX 9 3,1416 [R/S] => 3927 [X<>Y] 1250 Dieter |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)