Will My TI-82 do modular arithmetic?

Howdy.

I have to track time for work and I’ve just been doing it by start and finish. Now I’m getting these long lists of minutes worked that I have to add up and I’ve always had problems with that sort of addition.

I have my TI-82, but I’ve long since lost the instructions.

Will it do modular (or is it modulo?) arithmetic?

If so, how do I do it?

Please advise,
jsh

No, it does not have “modular arithmetic” built in (hardcoded). You can write a program. If you would like me to help you write a program, let me know. I would write one right now but I am unsure of what capabilities you want it to have and what you want it to do…
Write to me at westexas@gaggle.net

I know I had to write a modulo function (the equivalent of C’s % operator) when I used a TI. I have forgotten the nuances of TI BASIC, but as I recall it was quite simple:


/* Pseudocode */
mod(p,q) {
   x = p / q;
   return p - (q * int(x));
   /* Where int() discards the fractional part */
}

If you want more, I have written a small group of functions for my HP that will do the kind of time arithmetic you seem to want. I can convert them to pseudocode if you want me to.

See http://education.ti.com/us/product/tech/82/guide/82guideus.html.

The modulus operator distributes over addition, subtraction, multiplication and integer division, so unless you’re having overflow problems, you can get away with a single mod call at the end of your arithmetic.

Huh? Man, I am the apotheosis of non-hyperactive ADD: can you put that into steps I can follow?

(If it’s any consolation, within a month I am going to be going toe-to-toe with the biggest piece of shit lawer Meijer can muster to explain why I’m so bad w/ tracking the time I’ve spent on their project. So don’t think it’s a cop out.)

I have a TI-83, so I’ll assume it’s all the same.

You have a number, say 894. You want that number, mod something, let’s say 60.

Type 894.
Press Enter.
Type “-” (not to be confused with the “negative” key) then 60 and you’ll see “Ans-60” which means “The last answer calculated minus 60”
Press enter, and you’ll see the result of 894-60 which happens to be 834
Press enter again and you’ll see the result of Ans-60, but now “Ans” is 834, so it’ll say 774 this time.
Keep pressing enter until you get to 234, then 174, then 54, which is less than 60, so you’re done.

You can write a program that does all this automatically. I’m too tired to write it out right now, but it’s not overly difficult.

It means you can do all your calculations and then apply the modulo to the result. You don’t need to keep applying the modulo function at every step, unless the results are getting so large you are overflowing the space allotted per variable.

But on a programmable TI, such overflow is pretty unlikely.

Nevermind. I guess I’m not too tired. It’s even easier than I thought. If you’re calculating x mod y, then x is Ans and y is N (the number it asks for).



:Ans -> X
:Prompt N
:While 1
:If X<N
:Then
:Disp X
:Stop
:Else
:X-N -> X
:End
:End

where “->” is the “store” arrow.

So using the same example, you would do all your calculations, and the TI would spit out “894.” Then you would run this program, inputting 60 when you see “N=?” and it would give you your answer (54).

For anyone who’s still here, but not following the code/pseudocode, this is a completely different method than Derleth’s program. So there’s at least one other way of coding this for the TI.

Okay—the boss needed the latest time hour calculations ASAP, right AFTER I posted the question, of course, so I just added the minutes until they broke sixty and then subtracted sixty and marked one tally on my hour column every time that happened. So if I had 0:45 + 0:30, I’d add to get 75, from which I subtracted to get 0:15 plus one in my hour tally. It ended up taking a bit longer I’m sure, but I’m confident I ended up w/ the correct amount of time.

Does that sound basically efficient?

(Short of emailing westexas, which I haven’t done because the calculater is at work and I’m not and I’m replying while hammered. I’ll see about shooting off that email on Monday.)

Now that you mention that method, I just realized something else. The TI’s have a DMS function. That stands for degrees, minutes, seconds – a way of measuring angles with greater accuracy than degrees alone. There are 60 minutes in a degree, and 60 seconds in a minute. Confused? Don’t worry about it, just do this:

Let’s say you have 894 minutes, again. Type 0°894’ (the degree and minute signs are in the Angle menu – press 2nd, apps) and you get 14.9. Now press “>DMS” (also on the Angle menu) and you get 14°54’

This is even better, since it gives you both minutes AND hours. Anyway, I think you have a few different methods now. Hopefully one of them makes sense to you.

Yeah! It just occured to me that I may not want to do math mod 60, instead do I want to do use a base-60 number system? Since mod 60 drops every unit of sixty, but I want to save every unit of 60 and add that to my total, that gives me a base-60 number system, right?

That’s probably a different problem…

Well, not really, but it would get you the right answers as long as you didn’t get confused in the process.

I think the DMS function would be the most efficient in this specific instance, and my function is the most efficient general-purpose modulo function anyone’s yet posted here.

What would be most useful is a function that returns two values, the integer part of the quotient and the remainder.

BTW, my function as TI BASIC runs like this:



:Prompt P
:Prompt Q
:P/Q -> X
:Disp P-(Q*iPart(X))


Of course, since X is a global, running this program will alter its value.

Not really. The only difference is that you don’t throw away the integer part of the quotient, like the modulo function does.

Anyway, that is the basic idea behind the DMS function on your TI. If your TI can add two DMS values (like 14º15’+0º45’=15º0’) then you don’t really need to write any programs at all.