Repeating Decimals
|
01-19-2018, 03:58 AM
(This post was last modified: 01-23-2018 02:31 AM by Joe Horn.)
Post: #7
|
|||
|
|||
RE: Repeating Decimals
Oh my goodness, it hit me today that the whole headache of finding the multiplicative order of 10 (mod X) can be entirely avoided! All we have to do is:
123/208 EDIT: STEP ZERO: Fully reduce the fraction, if your machine doesn't automatically do that for you (like RPL machines do). [Thanks to tgray for catching this oversight!] First, find how many digits after the decimal point don't repeat: 208 = 2^4 * 5^0 * 13, and MAX(4,0) is 4, so any integer divided by 208 will have 4 digits after the decimal point which don't repeat. Secondly, find the integer part of the answer: 123 208 IDIV2 --> 0 123 <-- Integer part of answer (on level 2 of the stack; the remainder 123 is on level 1 of the stack). Thirdly, print that 0 and a decimal point here. Fourthly, do 10 * 208 IDIV2 four times to get the 4 digits which don't repeat, printing each digit as it's calculated: 10 * 208 IDIV2 --> 5 190 <-- Begin non-repeating part 10 * 208 IDIV2 --> 9 28 10 * 208 IDIV2 --> 1 72 10 * 208 IDIV2 --> 3 96 <-- End repeating part. Save that remainder. Fifthly, print the underscore character "_" to separate the non-repeating digits from the repeating digits. Sixthly and finally, repeat 10 * 208 IDIV2, printing each digit as it's calculated, until that saved remainder reappears. 10 * 208 IDIV2 --> 4 128 10 * 208 IDIV2 --> 6 32 10 * 208 IDIV2 --> 1 112 10 * 208 IDIV2 --> 5 80 10 * 208 IDIV2 --> 3 176 10 * 208 IDIV2 --> 8 96 <-- There it is! STOP. Done. So 123/208 = 0.5913_461538 (using the underscore to mean "here begin the repeating digits"). Holy smokes, that's EASY to program in RPL! No "multiplicative order" routine is necessary! Writing it in HP PPL is left as an exercise for the student. <0|ΙΈ|0> -Joe- |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)