The Museum of HP Calculators

HP Forum Archive 06

[ Return to Index | Top of Index ]

HP-12C trigonometrics
Message #1 Posted by Ex-PPC member on 11 Oct 2001, 2:47 p.m.

Hi, I've recently got an HP-12C, and I'm trying to write a program for it implementing all six trigonometric functions that it lacks, namely sin, cos, tan, and their inverses. Now, I'm pretty sure this must be old hat for everyone, but I've never seen before such a program. I would be grateful if someone could point me where to find that program, so that I could compare with mine and see how its author solved the many troubles I've suffered while implementing it, namely extreme shortage of program memory to implement all 6 functions at once at the greatest possible accuracy (8 decimal places or better) for all the range of input values.

My actual beta version implements everything except the arc cosine function (no big deal, it can be easily computed as pi/2-arc sine) with 8-10 decimal places accuracy, and uses no numbered registers at all, but I would love to see how other coped with this subject.

Re: HP-12C trigonometrics
Message #2 Posted by W. Bruce Maguire II on 11 Oct 2001, 5:20 p.m.,
in response to message #1 by Ex-PPC member

Ex-PPC member (are you under-cover?):

Can you post the program? I would love to see it, as would others, I'm sure.

For the good of us all, maybe we'll start a sort of informal contest, where programs are presented for the 12C and 17BII to acomplish the trig. and inverse trig. functions. Seems reasonable to me---these two calculators are current, and both have advantages over the 32SII (the only current RPN scientific) excepting some key scientific functions. I would say that the 12C has a landscape-format advantage (for many people---I prefer the portrait format myself) and a number-display advantage, and the 17BII has numerous advantages over the 32SII (the 17BII is simply a much more powerful machine).

I recently submitted my solution for the 17BII, but I limited my solution to the region [0, PI/2]. I'm sure my program could be improved, but there doesn't seem to be an overwhelming interest...


Re: HP-12C trigonometrics
Message #3 Posted by Ex-PPC on 11 Oct 2001, 9:34 p.m.,
in response to message #2 by W. Bruce Maguire II

Thanks for your kind words. I don't know how to post the program here, I guess a raw listing in a posted response would get weirdly formatted, if at all.

The main difficulties I've found stem from the HP-12C's extremely limited programming capabilities. You just have to try and fit all 6 trig functions in 99 bytes ! That wouldn't be so bad as it seems were it not for the fact that you don't have labels, nor flags, only x<=y and x=0 tests (which forces you to *substract* two values and compare the result to zero, when you actually wanted to compare one against the other), no indirect adressing, no increment/decrement instructions, and, most decisively, you don't have subroutine capability (!!). That alone is really the ultimate coup-de-grace to fit everything accurately in so little memory. Matter of fact, I haven't succeeded, I just can't find room enough to include the arc cosine. Only the fact that it's easily computed from the arc sine (pi/2-arcsin) saves the day. That's why I'm so interested in looking at other people's solutions to this particular programming issue. I'm sure some must exist already.

Re: HP-12C trigonometrics
Message #4 Posted by Jim L on 11 Oct 2001, 9:57 p.m.,
in response to message #3 by Ex-PPC

You can do it like:

program line 1
program line 2
Re: HP-12C trigonometrics
Message #5 Posted by David Smith on 11 Oct 2001, 9:33 p.m.,
in response to message #1 by Ex-PPC member

If you can find a copy of the Collected Algorithms of the ACM (Association for Computing Machinery) from around 1976 +/- 3 years or so there is a "continued fraction" algorithm. As I rememeber it produces a couple of numbers that depending upon how you combine them gives you all the trig funcions, e^x, and hyperbolics. It has been a long time since I played with it but it was rather short, fast, and most interesting.

Re: HP-12C trigonometrics
Message #6 Posted by Jan on 12 Oct 2001, 9:55 a.m.,
in response to message #5 by David Smith

Try: M. Abramowitz and I. Stegun. Handbook of Mathematical Functions. Dover, 1972.

There you will find a lot of very useful approximations, easy to program for different levels of accuracy.


Re: HP-12C trigonometrics
Message #7 Posted by Vieira, Luiz C. (Brazil) on 13 Oct 2001, 9:32 a.m.,
in response to message #6 by Jan

I have once written a very short program for the HP38C that computed SIN, COS and TAN (no inverses), less than 15 steps. At that time I was studying for Electrical Eng. (long, long time ago...) and I have lost it. I remember computing Taylor series for sine and cosine (n! saved the day) and dividing both to compute tangent. It would fit perfectly in an HP12C.

I also remembered using TVM procedure to estimate energy consumption x production in a power plant. How many good stuff we had to do at that time...

Will anybody share the programs with us? I would if I had, I remember not even noting the steps, as the program was of no specific need of mine (only for that charming 19 Y.O. girl I cannot really forget the thankful face when my program ran smoothly on her HP38C).

Re: HP-12C trigonometrics
Message #8 Posted by Nenad Vulic (Croatia) on 13 Oct 2001, 11:02 a.m.,
in response to message #7 by Vieira, Luiz C. (Brazil)

Luiz Claudio, if we put trigonometrics aside, it would be more interesting to know what happened later, with respect to that 19 Y.O. 8-) ?

Re: HP-12C trigonometrics
Message #9 Posted by Vieira, Luiz C. (Brazil) on 13 Oct 2001, 11:34 a.m.,
in response to message #8 by Nenad Vulic (Croatia)

She got her Engineering graduation and... left many gratefull memories. I would like knowing where is she, right now. Just memories... Anyway, who does not have them?


(Hey, do you still need that material about the 41CX? Let me know...)

Re: HP-12C trigonometrics (Been there, done that)
Message #10 Posted by Michael Blankenship on 16 Oct 2001, 11:07 a.m.,
in response to message #7 by Vieira, Luiz C. (Brazil)


I have already posted the trig functions earlier here. See Forum Archive 6 entitled "Add trig functions on HP17BII, etc.? (You can)" for the source. I incorrectly stated that they were the Maclaughlin series--they're actually the Maclaurin series. They work quite well in both directions.

FYI and good luck, M.

No, we haven't "Been there, done that"
Message #11 Posted by W. Bruce Maguire II on 16 Oct 2001, 12:50 p.m.,
in response to message #10 by Michael Blankenship


You seem to have missed the point. I, too, posted information on programming trig. functions into the HP-17BII, except my algorithms also include the INVERSE trig. functions, which is something that we are talking about here. I also included a full program listing. Look in the current forum page for:
Improved TRIG. and INVERSE TRIG. functions for the HP-17BII (Posted Sept. 26, 2001)

I actually had posted my first post on trig. functions for the 17BII on 7/31/2001 (horrible code---see the later post for details). I then followed it up on 9/26/2001 with a vastly superior implementation than the dumb one I first posted. Your article was posted on 9/3/2001. Please look at my 9/26/2001 post for an example of formatting that I think is acceptable for HP-17BII listings. As soon as you go into the Forum, there is a hyper-link to advanced formatting techniques.

The point here, is come up with code to fit these functions into a 12c. The 12c is a completely different programming beast than the 17BII, and is much more limited. That is what this thread is about.

If you are able to implement your algorithms on a 12c for all the trig. AND INVERSE TRIG. functions, please post a 12c listing!


[ Return to Index | Top of Index ]

Go back to the main exhibit hall