The Museum of HP Calculators

HP Articles Forum

[Return to the Index ]
[ Previous | Next ]


Improved TRIG. and INVERSE TRIG. functions for the HP-17BII

Posted by W. B. Maguire II on 26 Sept 2001, 12:40 p.m.

Improved TRIG and INVERSE-TRIG functions for the HP-17BII

+------------------------------------------------------------------------------+
| If _anyone_ finds this post useful, please validate me with a response!  ;-) |
+------------------------------------------------------------------------------+

Background:

OK. I really like the HP-17BII. It has the great Pioneer dimensions. It has a nice, big 22-character display. It has dedicated soft-keys and a second line in the display for their labels. (I think I prefer this soft-key implementation to the 42's overloading of the soft-keys. I'll be in a menu and think I have access to those functions on the top row of keys. The dedicated soft keys [pioneered by the 28c/s] seem to be more intuitive to me.)

Anyway, being an engineer, I break out in a rash if I don't have access to the trigonometric and inverse-trig. functions.

So, to borrow from "Animal House":
I think that this situation absolutely requires a really futile and stupid gesture be done on somebody's part. And I'm just the guy to do it.

Several weeks ago, I posted my routines for calculating the TRIG. and INVERSE TRIG. functions. Unfortunately, I didn't realize that the factorial function existed on the 17BII! Duh! I also did not know about the undocumented "L()" and "G()" (Let and Get) functions. I strongly encourage anyone who would like to program the 17BII to buy the CD-ROMs from the HP Museum in order to obtain the "Technical Applications" book for the 27S and 19B. The undocumented "Let" and "Get" functions are described, as well as methods of executing looping---these functions open-up programming options that were not conceivable before! For instance: definite loops and invisible, temporary variable assignments. Definitely a MUST READ! By the way, in my opinion, these functions completely put to rest the question of whether the 17BII and 19BII are "programmable"---they absolutely are!

So, anyway, here is my self-redemption for those embarassing, brute-force routines.

Equation Descriptions:

The following equations for the HP-17BII calculate the TRIG. and INVERSE TRIG. functions. I originally had larger formulas that combined SIN,COS,TAN into one equation, and ASIN,ACOS,ATAN into one equation. But, I wanted to minimize the "CALC" time for these formulas, since it's just overhead. As a result, I have left out the TAN function, because it is very easy to enter the angle, press [SIN] then [COS] then the divide key. Since ASIN and ACOS are so similar, they are in one equation, but ATAN is just different enough to (in my mind) justify a seperate equation.

Another approach---which I still might consider---is to cram all desired functions into one single equation, and then try not to leave the solve menu. Getting back into the solve menu would take literally minutes of "CALC" time!

In the interest of accuracy, the inverse trig. functions are divided into multiple domains, so that the polynomials converge faster. The ASIN and ACOS have two domains: [0,PI/4] and [PI/4,PI/2]. The ATAN is a little more complicated; its domains are: [0,~0.3927], [~0.3927,~1.1781], and [~1.1781,inf). The accuracy for the ATAN function is MUCH better than a tangent Taylor series approximation (and therefore MUCH faster). After the routine listings, I have computed (using Matlab) the worst-case accuracy of the equations, given various maximum-exponent values (in the polynomial series).

In the following equations: "SIGMA" means the sigma symbol:

   (In the ALPHA menu: 
   [WXYZ][OTHER][MORE], 
   then the second button)
"ANGLE" means the angle symbol:
   (In the ALPHA menu: 
   [WXYZ][OTHER][MORE][MORE][MORE][MORE],
   then the fifth button)
The formula for the SIN and COS was kindly supplied by Kynes.

Equation Listings:

DEGREES~RADIANS:
   DEG/180*PI=RAD

SIN,COS,D~R: IF(S(SIN): SIGMA(N:0:9:1:(-1)^N* ANGLE^(2*N+1)/FACT(2N+1))-SIN : IF (S(COS): SIGMA(N:0:9:1:(-1)^N* ANGLE^(2*N)/FACT(2N))-COS : DEG/180*PI-RAD ) )

ASIN,ACOS,D~R: IF(NOT (S(DEG) OR S(RAD)): 0* IF(X<.7071: L(R3:X)+ IF(S(ASIN): L(R1:0)+L(R2:1) : L(R1=1)+L(R2=-1) ) : L(R3:SQRT(1-SQ(X)))+ IF(S(ASIN): L(R1=1)+L(R2=-1) : L(R1:0)+L(R2:1) ) ) +G(R1)*PI/2+G(R2)*( G(R3)+ SIGMA(N:3:31:2: (FACT(N-2)*(G(R3))^N/ (2^(N-2)*FACT((N-3)/2)*FACT((N-1)/2)*N))) ) - IF(S(ASIN): ASIN : ACOS ) : DEG/180*PI-RAD )

ATAN,D~R: IF(NOT (S(DEG) OR S(RAD)): 0* IF(L(AA:ABS(SQ(X)-1)/(SQ(X)+1))<.7071: L(R1:.5)+ L(R2:SGN(X-1)/2)+ L(R3:G(AA)) : L(R1:.5+SGN(X-1)/2)+ L(R2:.5-G(R1))+ L(R3:2*X/(SQ(X)+1)) ) +G(R1)*PI/2+G(R2)*( G(R3)+ SIGMA(N:3:31:2: (FACT(N-2)*(G(R3))^N/ (2^(N-2)*FACT((N-3)/2)*FACT((N-1)/2)*N))) ) -ATAN : DEG/180*PI-RAD )

Sample Calculations:

Sin(30 degrees):
"CALC" the SIN,COS equation, then press:

30[DEG][RAD][STO][angle-key][SIN]
Answer = 0.5000
---------------------------------

Tan(45 degrees):
"CALC" the SIN,COS equation, then press:

45[DEG][RAD][STO][angle-key][SIN][COS][divide-key]
Answer = 1.0000
---------------------------------

ArcSin(0.5):
"CALC" the ASIN,ACOS equation, then press:

0.5[X][ASIN]
Answer = 0.5236 radians
To get the answer in degrees, press:
[STO][RAD][DEG]
Answer = 30.000 degrees
---------------------------------

The ArcTan function works the same as the ArcSin and ArcCos, but you need to "CALC" the ATAN equation, rather than the ASIN,ACOS equation.

Accuracy Calculations:

For the following accuracy calculations, Matlab was used. Therefore the following accuracies are closer to the theoretical accuracy of the previous algorithms. 'Epsilon'---in the computational context---means the smallest number (in a computer) that may be added to one, and yield a result that is greater than one. It is a measure of the precision that the computer uses to represent numbers (really the number of bits for the mantissa). The Epsilon for the HP-17BII is about 5e-12. (I presented an equation to show this for the HP-17BII in a separate posting.) The Epsilon for Matlab is about 2e-16. Therefore, the HP-17BII will not be any more accurate than 5e-12 in the best case (not O(10^-16) as indicated in some cases below).

For the SIN,COS equation (COS accuracy is the same as SIN):
-----------------------------------------------------------
Highest exponent of  5, gives maximum normalized     SIN error of 5.62e-08
Highest exponent of  7, gives maximum normalized     SIN error of 6.02e-12
Highest exponent of  9, gives maximum normalized     SIN error of 5.55e-16
Highest exponent of 11, gives maximum normalized     SIN error of 5.41e-16

Highest exponent of 5, gives maximum normalized SIN/COS error of 4.84e-03 Highest exponent of 7, gives maximum normalized SIN/COS error of 6.76e-07 Highest exponent of 9, gives maximum normalized SIN/COS error of 3.67e-11 Highest exponent of 11, gives maximum normalized SIN/COS error of 1.21e-12

For the ASIN equation (ACOS accuracy is the same as ASIN): ---------------------------------------------------------- Highest exponent of 15, gives maximum normalized ASIN error of 7.10e-05 Highest exponent of 17, gives maximum normalized ASIN error of 3.03e-05 Highest exponent of 19, gives maximum normalized ASIN error of 1.32e-05 Highest exponent of 21, gives maximum normalized ASIN error of 5.78e-06 Highest exponent of 23, gives maximum normalized ASIN error of 2.57e-06 Highest exponent of 25, gives maximum normalized ASIN error of 1.15e-06 Highest exponent of 27, gives maximum normalized ASIN error of 5.19e-07 Highest exponent of 29, gives maximum normalized ASIN error of 2.36e-07 Highest exponent of 31, gives maximum normalized ASIN error of 1.08e-07 Highest exponent of 33, gives maximum normalized ASIN error of 4.95e-08 Highest exponent of 35, gives maximum normalized ASIN error of 2.29e-08 Highest exponent of 37, gives maximum normalized ASIN error of 1.06e-08 Highest exponent of 39, gives maximum normalized ASIN error of 4.92e-09 Highest exponent of 41, gives maximum normalized ASIN error of 2.30e-09

Accuracy for ATAN in the ATAN equation is the same as ASIN and ACOS.

Now, all the HP-17BII needs is an "Engineering" display mode!

Bruce.

Password:

[ Return to the Message Index ]

Go back to the main exhibit hall