(42S/DM42/Free42) Repeating decimals
|
01-23-2018, 01:41 AM
Post: #1
|
|||
|
|||
(42S/DM42/Free42) Repeating decimals
There was a recent thread on calculating repeating decimals. Joe Horn had a simple algorithm to do it, so I coded it for the DM42. It works on Free42 as well - not sure how well it would work on an actual 42S.
There are two functions, IDIV2 and RDEC. IDIV2 is a standalone function that replicates the function from the 50g (I think). Input is the numerator on Y and the denominator on X. The results are: T: input numerator (a) Z: input denominator (b) Y: integer part of a/b X: remainder of a/b RDEC uses IDIV2 to implement Joe's algorithm and display the result of Y/X in the alpha register using the notation x.yyyy_rrrr... where 'rrr' is the repeating part of the decimal. It's not always perfect - try 11632/864. Doesn't catch the first period of the repeating decimal. I also use most of the R00 to R09. Sorry for my sloppiness there. I should clean these up to make them more logical (or use named variables) but I didn't. R00: temp for calculating R01: b R02: a R04: number of factors of 2 in b R05: number of factors of 5 in b R07: temp for calculating R08: The remainder that signifies the end of the repeating part (96 in Joe's example) R09: the max of R04 and R05 - used as a decrementing counter Input is numerator (a) in Y and denominator (b) in X. Output is: A: repeating decimal Z: a Y: b X: a/b Code:
|
|||
01-23-2018, 07:01 AM
Post: #2
|
|||
|
|||
RE: (42S/DM42/Free42) Repeating decimals
I tried on a real hp42s, it works like a charm. It is quite fast and usable.
Thank you. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)