Trigonometric Functions for the HP-38C/HP-12C
|
03-25-2016, 03:30 AM
Post: #1
|
|||
|
|||
Trigonometric Functions for the HP-38C/HP-12C
Some time ago, Gerson Barbosa wrote a really nice program to compute Trig functions on the HP-12C and its predecessor, the HP-38C.
I'm interested in the source of the coefficients: -3.333324820E-01 STO 1 1.998722722E-01 STO 2 -1.397054038E-01 STO 3 -8.860960894E-07 STO 4 1.349561365E-11 STO 5 -9.716369450E-17 STO 6 More precisely, does anyone know if there exists a listing of these coefficients that show more digits? I now have an emulator of the HP-38C (iPhone) that allows me to store constants of up to 15 or 16 digits, instead of 10 on the original machines. I've already taken care of the one in Reg 0 as I just took a 16 digit Pi and divided it by 180. My thinking is that if I can use longer coefficients I can probably get more accuracy. Although this program has a high degree of accuracy to begin with. Thanks! Regards, Bob |
|||
03-25-2016, 04:51 AM
(This post was last modified: 03-25-2016 04:51 AM by Gerson W. Barbosa.)
Post: #2
|
|||
|
|||
RE: Trigonometric Functions for the HP-38C/HP-12C
(03-25-2016 03:30 AM)bshoring Wrote: Some time ago, Gerson Barbosa wrote a really nice program to compute Trig functions on the HP-12C and its predecessor, the HP-38C. Unfortunately more digits won't help here. In order to improve the accuracy you would need more constants, but then this wouldn't be possible on the HP-12C/38C using this approach, given their limited memory. I was able to get much better accuracy and functionality on the HP-12C Platinum whose 20 registers are always available, even when all 400 programming steps are fully used: http://www.hpmuseum.org/cgi-sys/cgiwrap/...i?read=654 The linked TurboBCD program, for instance, provides 17-digit accuracy. But it required the computation of 18 constants, 10 for arctangent and 8 for sine: http://www.geocities.ws/gwbarbosa/prgms_4.html Here, starting at page 8, is an explanation of the method: http://www.research.scea.com/research/pd..._GDC02.pdf Thank you for your interest in this old program of mine! Gerson. |
|||
03-25-2016, 02:54 PM
Post: #3
|
|||
|
|||
RE: Trigonometric Functions for the HP-38C/HP-12C
Gerson, thanks for your explanation. I'm having fun with the program which runs lightning fast on this emulator.
Regards, Bob |
|||
03-25-2016, 03:14 PM
(This post was last modified: 03-25-2016 07:08 PM by Gerson W. Barbosa.)
Post: #4
|
|||
|
|||
RE: Trigonometric Functions for the HP-38C/HP-12C
(03-25-2016 02:54 PM)bshoring Wrote: Gerson, thanks for your explanation. I'm having fun with the program which runs lightning fast on this emulator. Bob, you're most welcome! Here are the 16-digit constants for sine: -8.86096047786772E-07 +1.34958277546461E-11 -9.73258222092326E-17 Regardless the exta digits, the maximum error should stay around 2E-10. Anyway, some rounding errors should be eliminated, so these should be worth trying. Regards, Gerson. Edited to correct a mistake (2E-10, not 2E-9). |
|||
03-25-2016, 09:22 PM
(This post was last modified: 03-26-2016 07:25 PM by Gerson W. Barbosa.)
Post: #5
|
|||
|
|||
RE: Trigonometric Functions for the HP-38C/HP-12C
These might give maximum absolute errors around 1.2E-10 and 8.8E-10 for sine and arctangent, respectively:
+1.74532925199433E-02 STO 0 -3.33332558903409E-01 STO 1 +1.99913266300000E-01 STO 2 -1.40254920000000E-01 STO 3 -8.86096146249340E-07 STO 4 +1.34958277500000E-11 STO 5 -9.73259000000000E-17 STO 6 P.S.: I will check the arctangent constants later. .9999 GTO 39 R/S --> 89.18970856 asin ok .9999 GTO 46 R/S --> 0.8102914371 acos ok .9999 GTO 52 R/S --> 44.997(06196) P.P.S.: These are better: -0.3333323779 STO 1 0.19987227 STO 2 -0.139705 STO 3 1 GTO 52 R/S --> 45.00000(288) .9999 GOTO 52 R/S --> 44.99713(794) .9 GOT0 52 R/S --> 41.98721(134) |
|||
03-26-2016, 08:21 PM
Post: #6
|
|||
|
|||
RE: Trigonometric Functions for the HP-38C/HP-12C
Gerson,
Thanks for the updated constants. By loading these values I'm getting excellent results: R0: 1.74532925199433E-02 R1: -0.3333323779 R2: 0.19987227 R3: -0.139705 R4: -8.86096146249340E-07 R5: 1.349582775E-11 R6: -9.73259E-17 The emulator for the HP-38C allows RCL arithmetic so in some cases I've been able to combine steps, so I can put GOTO instructions at the beginning so now I can use: COS(x): [R/S] SIN(x): [R/S] [x<>y] TAN(x): [R/S] [/] ASIN(x): [g] [GTO] 02 [R/S] ACOS(x): [g] [GTO] 03 [R/S] ATAN(x): [g] [GTO] 04 [R/S] This (iOS) emulator is so fast as soon as I hit R/S I see the result. Regs are not shared with program steps so all are available. Fortunately, when I save the program the constants & display settings are saved as well so I don't have to reload anything after I use other programs. The Trig functions are working like a charm. Thanks so much! P.S. If you get an RPN-38 CX emulator let me know. I'll be happy to send the modified program listing. Regards, Bob |
|||
03-26-2016, 09:38 PM
(This post was last modified: 03-26-2016 09:56 PM by Gerson W. Barbosa.)
Post: #7
|
|||
|
|||
RE: Trigonometric Functions for the HP-38C/HP-12C
(03-26-2016 08:21 PM)bshoring Wrote: The Trig functions are working like a charm. Even better now! Thanks for the fun, even though today is still Easter Sunday Eve. Well, no programming tomorrow then :-) Gerson. Fast and Accurate Trigonometric Functions on the RPN-38 CX Simulator Code:
Usage: Trigonometric functions: Enter angles in degrees, -90 =< x <= 90 (*): R/S => cos(x) x<>y => sin(x) x<>y / => tan(x) GTO 35 R/S => arcsin(x) GTO 44 R/S => arccos(x) GTO 50 R/S => arctan(x) ------------------------------------------ 0.0001 R/S --> 1.000000000 ; cos(0.0001) x<>y --> 1.745329252E-06 ; sin(0.0001) / --> 1.745329252E-06 ; tan(0.0001) 0.9999 GTO 35 R/S --> 89.18960866 ; asin(0.9999) 0.9999 GTO 44 R/S --> 0.8102914371 ; acos(0.9999) 0.9999 GTO 50 R/S --> 44.99713507 ; atan(0.9999) Other examples: sin(0.01) = 0.9999999848 sin(0.01) = 1.745329243E-04 tan(0.01) = 1.745329270E-04 sin(30) = 0.8660254038 cos(30) = 0.5000000000 tan(30) = 0.5773502692 sin(60) = 0.500000000(1) cos(60) = 0.866025403(7) tan(60) = 1.73205080(8) sin(89.99) = 0.9999999848 cos(89.99) = 1.7453(37879)E-4 tan(89.99) = 5729.5(49544) sin(89.9999) = 1.000000000 cos(89.9999) = 1.7462(35540)E-6 tan(89.9999) = 572(660.4329) asin(0) = 0.000000000 acos(0) = Error 0 atan(0) = 0.000000000 asin(1e-10) = 90.00000000 atan(0.4142135624) = 22.50000000 atan(1) = 45.00000000 acos(0.8660254038) = 30.00000000 atan(50) = 88.85423716 ------------------------------------------ Forensic result: 9 R/S x<>y R/S R/S / GTO 50 R/S GTO 44 R/S GTO 35 R/S --> 9.000000272 ------------------------------------------ P.S.: (03-26-2016 08:21 PM)bshoring Wrote: The emulator for the HP-38C allows RCL arithmetic so in some cases I've been able to combine steps, so I can put GOTO instructions at the beginning so now I can use: If you replace register n with register 9 then you can save at least three steps, but I think this won't be enough. Anyway, the new labels (35, 44, and 50) are somewhat easier to remember. |
|||
03-27-2016, 02:43 AM
Post: #8
|
|||
|
|||
RE: Trigonometric Functions for the HP-38C/HP-12C
Gerson,
It looks like constants are required for R7 & R8. What do I need to store? Thanks, Bob Regards, Bob |
|||
03-27-2016, 03:08 AM
(This post was last modified: 03-27-2016 03:26 AM by Gerson W. Barbosa.)
Post: #9
|
|||
|
|||
RE: Trigonometric Functions for the HP-38C/HP-12C
(03-27-2016 02:43 AM)bshoring Wrote: It looks like constants are required for R7 & R8. What do I need to store? They've been included after the listing. Perhaps I should have left them outside the code box. Also, their positions have changed: ------------------------------------------ 1.745329252E-02 STO 0 ; pi/180 0.199999779 STO 1 ; Five coefficients of the arctangent polynomial -- there are seven of them, 1 and 1/3 are built into the program steps 84, 85 and 88. 0.142841665 STO 2 1.107161127E-01 STO 3 0.086263068 STO 4 0.05051923 STO 5 8.860961462E-07 STO 6 ; Three coefficients of the arcsine polynomial -- the first one is 1 x pi/180 (step 14) 1.349582775E-11 STO 7 9.73259E-17 STO 8 ------------------------------------------ Alternatively, but no significant differences: 1745329251 ENTER .99433 + g EEX 10 / STO 0 8860961462 ENTER .4934 + g EEX 16 / STO 6 ------------------------------------------ Regards, Gerson. |
|||
03-27-2016, 03:14 AM
Post: #10
|
|||
|
|||
RE: Trigonometric Functions for the HP-38C/HP-12C
Oh, now I see them. I didn't scroll down beyond that last line.
Thanks so much ! Regards, Bob |
|||
03-27-2016, 05:04 AM
(This post was last modified: 03-27-2016 05:05 AM by Gerson W. Barbosa.)
Post: #11
|
|||
|
|||
RE: Trigonometric Functions for the HP-38C/HP-12C
Bob,
I would suggest using the .n registers as they're less likely to be accidentally overwritten. Only now, twenty four hours later, I read about them in the CuVee website. I found the RCL arithmetic by chance this afternoon. Better read the manual first next time. With this plenty of registers there's no need to use any financial register. Some error handling still needed as you can see in the examples, but at least the accuracy of the inverse functions is now in line with the others. Hopefully no serious issues, but please let me know if you find any. Regards, Gerson. |
|||
03-27-2016, 11:08 PM
Post: #12
|
|||
|
|||
RE: Trigonometric Functions for the HP-38C/HP-12C
There are some mistakes in my examples above (mostly sine for cosine). Hopefully no more such mistakes in the new version here.
Note to moderators: despite the title, this thread should be moved to the Not quite HP Calculators - but related sub-forum as it actually applies to Willy R. Kunz's RPN-38 CX Simulator (if the OP doesn't mind). Thanks in advance. Gerson. |
|||
03-27-2016, 11:50 PM
Post: #13
|
|||
|
|||
RE: Trigonometric Functions for the HP-38C/HP-12C
[quote='Gerson W. Barbosa' pid='52957' dateline='1459028300']
My results on RPN-38 CX, using the original constants are below, after yours, Gerson. In a few instances the longer constants produced different results, which I've shown where there was a difference. 0.9999 GTO 35 R/S --> 89.18960866 ; asin(0.9999) 89.18970856 (mine) 0.9999 GTO 44 R/S --> 0.8102914371 ; acos(0.9999) same for mine 0.9999 GTO 50 R/S --> 44.99713507 ; atan(0.9999) same for mine Other examples: cos(0.01) = 0.9999999848 same for mine sin(0.01) = 1.745329243E-04 same for mine tan(0.01) = 1.745329270E-04 same for mine cos(30) = 0.8660254038 I got 0.8660254008 sin(30) = 0.5000000000 I got 0.5000000005 tan(30) = 0.5773502692 I got 0.5773502771 cos(60) = 0.500000000(1) I got 0.499999311 sin(60) = 0.866025403(7) I got 0.866025801 tan(60) = 1.73205080(8) I got 1.732053989 sin(89.99) = 0.9999999848 I got 0.999999987 cos(89.99) = 1.7453(37879)E-4 I got 1.597989268E-4 (1.597989379E-4 with longer constants) tan(89.99) = 5729.5(49544) I got 6257.864226 sin(89.9999) = 1.000000000 I got same cos(89.9999) = 1.7462(35540)E-6 I got 1.300050952E-5 (1.300049244E-5 with longer constants) tan(89.9999) = 572(660.4329) I got 76920.06211 asin(0) = 0.000000000 I got same acos(0) = Error 0 I got same atan(0) = 0.000000000 I got same asin(1e-10) = 90.00000000 I got ZERO for asin, 90 for acos atan(0.4142135624) = 22.50000000 I got same atan(1) = 45.00000000 I got same acos(0.8660254038) = 30.00000000 I got same atan(50) = 88.85423716 I got same ------------------------------------------ Forensic result: 9 R/S x<>y R/S R/S / GTO 50 R/S GTO 44 R/S GTO 35 R/S --> 9.000000272 I got same with original constants. But after adding the longer constants in R0 & R6, I get 9.000000282 ------------------------------------------ Regards, Bob |
|||
03-28-2016, 12:25 AM
(This post was last modified: 03-28-2016 02:52 AM by Gerson W. Barbosa.)
Post: #14
|
|||
|
|||
RE: Trigonometric Functions for the HP-38C/HP-12C
Bob,
Please take a look at the new version in the other sub-forum. I used four steps I've managed to free to implement error handling for asin(1). I should've added another constant for the sine polynomial instead. This requires only two steps and one register. The sine polynomial is less accurate than the arctangent polynomial. This shouldn't be difficult to do as the four new constants could be the same listed in the hp 12c Platinum article. I'm not sure if the results for cosine and tangent for arguments near 90 degrees will be significantly improved as I've used other formulas in the 12c platinum program. Regards, Gerson. P. S.: Done that (added extra constant to the sine polynomial using the aforementioned constants). Now I get tan(89.0000) = 57.289961(72) tan(89.9900) = 5729.57(8904) tan(89.9999) = 57205(2.5534) Asin(1) = 90 degrees is gone, now Error 0 shows up instead. But who needs it anyway? Sunday is almost over. Tomorrow I will recompute the constants, but no much more improvement should be expected. |
|||
07-12-2017, 03:17 PM
Post: #15
|
|||
|
|||
RE: Trigonometric Functions for the HP-38C/HP-12C
(03-25-2016 04:51 AM)Gerson W. Barbosa Wrote:(03-25-2016 03:30 AM)bshoring Wrote: Some time ago, Gerson Barbosa wrote a really nice program to compute Trig functions on the HP-12C and its predecessor, the HP-38C... I'm wondering whether there's a mistake at the beginning of this particular program for the 12c. At line 006 x<>y, what is supposed to be in the y register? The program doesn't put anything in there, so it would be any random number that was left in the stack before the program was started. I'm running this on a simulator and not getting results remotely close to what they should be. |
|||
07-12-2017, 05:00 PM
(This post was last modified: 07-12-2017 05:03 PM by Gerson W. Barbosa.)
Post: #16
|
|||
|
|||
RE: Trigonometric Functions for the HP-38C/HP-12C
(07-12-2017 03:17 PM)tiptongrange Wrote:(03-25-2016 04:51 AM)Gerson W. Barbosa Wrote: Unfortunately more digits won't help here. In order to improve the accuracy you would need more constants, but then this wouldn't be possible on the HP-12C/38C using this approach, given their limited memory. I was able to get much better accuracy and functionality on the HP-12C Platinum whose 20 registers are always available, even when all 400 programming steps are fully used: This was meant to preserve the original X register. From the linked article: 2) sin²(30) + cos²(30): Notice that the stack register X is always preserved, so there's no need to store intermediate results in simple chain calculations (one-level only), as in this example. Keystrokes Display 30 R/S 0.500000000 g x² 0.250000000 30 g GTO 090 R/S 0.866025404 g x2 0.750000000 + 1.000000000 Regards, Gerson. |
|||
07-12-2017, 06:01 PM
Post: #17
|
|||
|
|||
RE: Trigonometric Functions for the HP-38C/HP-12C | |||
07-12-2017, 07:21 PM
Post: #18
|
|||
|
|||
RE: Trigonometric Functions for the HP-38C/HP-12C
(07-12-2017 06:01 PM)Gerson W. Barbosa Wrote:(07-12-2017 03:17 PM)tiptongrange Wrote: I'm running this on a simulator and not getting results remotely close to what they should be. I don't think it does, I'm using one written by RML Tools. I'm having a couple of problems right at the very beginning of the program. First, if I enter 30 and then directly go to R/S without hitting the enter key, the first line of the program will append the 2 to the end of 30 making it the number 302. Second, if I hit enter first, on step 003 - Roll Down sends the 2 to the T register, then on step 004 - RCL .0 lifts the stack which loses the 2 off the top of the stack. Is this supposed to happen? Thanks for your help. |
|||
07-12-2017, 08:04 PM
Post: #19
|
|||
|
|||
RE: Trigonometric Functions for the HP-38C/HP-12C
(07-12-2017 07:21 PM)tiptongrange Wrote:(07-12-2017 06:01 PM)Gerson W. Barbosa Wrote: Does the simulator you're using faithfully replicate the Platinum? There's at least one subtle difference regarding stack lifting when compared to the classic 12C. That product is a simulator of the 12C, not an emulator; an emulator would be running the original firmware, and therefor should act identically. That program likely acts close to the 12C, but not identically. You should contact the seller and ask them how their program differs from a real 12C. Without that knowledge, you cannot tell how a given program will run. Some programs will run just fine, others may not since they were designed and tested on real 12C hardware or emulators. Specifically ask about the program's accuracy (same, worse or better than a 12C) and also about program mode. --Bob Prosperi |
|||
07-12-2017, 08:13 PM
Post: #20
|
|||
|
|||
RE: Trigonometric Functions for the HP-38C/HP-12C
(07-12-2017 07:21 PM)tiptongrange Wrote: I'm having a couple of problems right at the very beginning of the program. First, if I enter 30 and then directly go to R/S without hitting the enter key, the first line of the program will append the 2 to the end of 30 making it the number 302. Pressing R/S is supposed to enable stack lift, i.e. the 2 is not appended to the current number entry. Instead the entered value should get pushed to Y while the 2 is written to X as a separate number. That's how classic HPs behave, including the original 12C. I suppose this is also true for the 12CP but I can't say for sure. (07-12-2017 07:21 PM)tiptongrange Wrote: Second, if I hit enter first, on step 003 - Roll Down sends the 2 to the T register, then on step 004 - RCL .0 lifts the stack which loses the 2 off the top of the stack. Is this supposed to happen? Yes, sure. The first steps store a 2 in register 6 which then is no longer required, so it is moved out of the way – e.g. with a roll down which brings back the original content of X. The 2 now is in T and finally lost with the following RCL .0. Dieter |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 6 Guest(s)