The Museum of HP Calculators

HP Articles Forum

[Return to the Index ]
[ Previous | Next ]


HP16C Trigonometric Functions (no inverses so far)

Posted by Vieira, Luiz C. (Brazil) on 13 May 2003, 1:46 a.m.

I would like to mention the fact that the programs listed here were based on the excellent Viktor Toth's Trig program written for the HP12C. There are other excellent works, including Valentin Albillo's related Trigs for the HP12C (Tried and Tricky Trigonometrics), but I was a lot intrigued with the fact that Viktor Toth used neither n! nor yx to compute each element of the series. So, I decided to go further and I literally "dismantled" the program in its stack and registers components, step by step for two loops. And there they were: n! and yx in a consecutive multiplication "fashion". Amazing! I only saw this sort of "RPN engine" in another program written for the HP41, already mentioned here, to compute the roots of a second degree equation. I ported it to the HP11C sometime ago.

I thought the program would fit fine in the HP16C because the HP16C has neither n! nor yx. I just forgot that the HP16C has no storage arithmetic, and Viktor Toth's Trigs use it a lot (STO + n, STO n, etc.). After a few hours refining and shrinking I could reduce Viktor's routine to a single storage register, no arithmetic required, and some additional stack manipulation. Also one small subroutine was added as I managed to group a small five-steps repeated sequence. As the HP16C has labels and the subroutine demands a RTN (return) the original SIN, COS and TAN computing needed 39 steps against the 32 used in the HP12C. As the program uses only R0, there is a final 7-byte credit.

I did not inspect the inverses so far, but I promise I'll do it soon.

I'd like to thank Viktor Toth for the inspiring program, and Valentin Albillo for showing other possibilities exist.

Restrictions applied here are the same ones applied to Viktor's Trigs, and I repeat them here:

The program fails for arguments equal to zero; For arguments outside the range of -PI/2 < x < PI/2, resulting cosine and tangent sign may not be correct; Due to rounding effects, accuracy may be less than desirable for arguments with a large absolute value (> PI) and for arguments near n*PI/2 (n = integer),

The Listing

001 g LBL F
002   ENTER
003   ENTER
004   STO 0
005 g 1/x
006   ENTER
007 g LBL 0
008   GSB 2
009 g R^
010   GSB 2
011   Rv
012   -
013   RCL 0
014 g x=y
015   GTO 1
016   Rv
017   STO 0
018 g LSTx
019   CHS
020   Rv
021   Rv
022   GTO 0
023 g LBL 2
024   +
025 g LSTx
026   Rv
027   
028 g LSTx
029 g RTN
030 g LBL 1
031   ENTER
032   
033 g LSTx
034   ENTER
035   
036   -
037 g V (sqrt)
038   
039 g LSTx
040 g RTN

Usage[

The calculator MUST be in FLOATing point mode:

[f][FLOAT] 4
[BSP]        (to clear display contents)
[g][CF] 5    (if flag 5, G annunciator, is set; not strictly necessary)

Given input angle (radians) x in X-register and pressing [GSB][F] we have:

Stack   Value
 T      irrelevant
 Z       sin(x)
 Y       tan(x)
 X       cos(x)
I'd appreciate any comments, suggestions, corrections, etc. The program runs correctly in my HP16C, but there may be errors after typing it in.

Thanks.

Password:

[ Return to the Message Index ]

Go back to the main exhibit hall