(12C) Decimal to Fraction
|
08-09-2018, 09:27 AM
(This post was last modified: 08-09-2018 10:35 AM by Dieter.)
Post: #30
|
|||
|
|||
RE: (12C) Decimal to Fraction
(08-08-2018 10:26 PM)Albert Chan Wrote: Below is the patched code: I have transcoded this for the 35s. Let me add a few remarks: First I think that q can also be calculated via q = c – (c–u) mod v. Can you confirm this? Also I do not quite understand why earlier code (and Joe's as well) used the CEIL function while here it's the FLOOR (or INT) function. Thomas even calculated 1+INT() which in most cases is the same as CEIL... but not for integer arguments. Then I wonder how exactly this Python diff() command works. Its arguments here are just the decimal input and a denominator – but not the corresponding numerator. So how does this work in detail? For instance, what is the value for diff(pi, 106) and diff(pi, 113)? In a calculator implementation first the numerators for the two possible results (denominators v and q) are calculated and then the errors are compared. These errors are evaluated by abs(input – numerator/denominator). This may lead to inaccuracies due to digit cancellation. Think of the √2 example (577/408 vs. 816/577). Is there a better way to compare the two possible fractions? Finally the code currently rejects integer input (which would lead to a division by zero). But can't this be trapped? For instance by leaving the while-loop if f=0? Or simply return v=1 if F is an integer? Dieter |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)