HP Forums

You're currently viewing a stripped down version of our content. View the full version with proper formatting.

```Here is a new trigonometric functions program for the new 12C Platinum. Are there another
designed specifically for this calculator? This is based on MiniMax Polynomial Approximation
(Thanks to Valentin Albillo who's shed some light on the subject) and drastic range
reductions ([0..pi/12] for arctangent function). The program is focused on accuracy and easy
of use. Arguments are entered in degrees and there is an entry-point for each function.
There are neither constants to be previously stored nor initialization routines. Placing the
constants directly into the program rather than recalling them from registers slows down
program execution but considering the new 12C Platinum is faster, this should not be a
problem. Actually this program has not been tested on the new 12C Platinum. Instead, it has
been tested with a very close version suitable for the 15C. Hopefully, I have made no
mistakes in adapting it to the Platinum. I just hope the new Platinum is at least five times
faster than the golden 12C so no function takes longer than two to three seconds to run.
Cos(x) is calculated as Sin(90-x) for the sake of accuracy. As the program is more than 255
lines long it will not work on the old Platinum unless some modifications are made (such as
replacing the last two or three constants in the program for registers recalls).
The accuracy is comparable with that of the HP-35. Cos(x) is calculated as Sin(90-x) for the
sake of accuracy. The program gives at least nine significant figures, many times matching
the 15C results. Also, the stack register X is always saved. So, the following expression
asin(acos(atan(tan(cos(sen(9))))))
may be evaluated as:
9 R/S GTO 090 R/S GTO 100 R/S GTO 153 R/S GTO 137 R/S GTO 119 R/S
The result in the 15C with the equivalent program is 8.999661629
That's all for the while,
Gerson.

TRIGONOMETRIC FUNCTIONS ON THE 12C PLATINUM
001	2	055	.	109	x<>y	163	1	217	1
002	STO 1	056	8	110	RCL 4	164	g LASTx	218	4
003	Rv	057	1	111	GTO 093	165	g x<=y	219	2
004	x<>y	058	7	112	x<>y	166	GTO 169	220	8
005	STO 4	059	7	113	RCL 4	167	1/x	221	3
006	x<>y	060	6	114	x<>y	168	9	222	7
007	STO 2	061	4	115	/	169	0	223	9
008	g x^2	062	1	116	RCL 3	170	STO 1	224	6
009	ENTER	063	7	117	x<>y	171	x<>y	225	-
010	ENTER	064	3	118	GTO 000	172	2	226	*
011	ENTER	065	EEX	119	x<>y	173	ENTER	227	.
012	4	066	3	120	STO 4	174	3	228	1
013	.	067	CHS	121	x<>y	175	SQRT	229	9
014	4	068	+	122	ENTER	176	STO 3	230	9
015	5	069	RCL 2	123	g x^2	177	-	231	9
016	0	070	*	124	1	178	x<>y	232	9
017	2	071	ENTER	125	-	179	g x<=y	233	9
018	CHS	072	g x^2	126	g x=0	180	GTO 192	234	8
019	EEX	073	4	127	GTO 132	181	ENTER	235	3
020	2	074	*	128	CHS	182	ENTER	236	2
021	0	075	CHS	129	SQRT	183	RCL 3	237	+
022	CHS	076	3	130	/	184	*	238	*
023	*	077	+	131	GTO 156	185	1	239	3
024	5	078	*	132	x<>y	186	-	240	1/x
025	.	079	RCL 1	133	9	187	x<>y	241	-
026	5	080	2	134	0	188	RCL 3	242	*
027	5	081	g x<=y	135	*	189	+	243	1
028	3	082	GTO 087	136	GTO 268	190	/	244	+
029	8	083	Rv	137	x<>y	191	3	245	RCL 3
030	3	084	g x=0	138	STO 4	192	0	246	*
031	9	085	GTO 112	139	x<>y	193	STO 2	247	5
032	EEX	086	GTO 107	140	g x=0	194	x<>y	248	7
033	1	087	Rv	141	GTO 150	195	STO 3	249	.
034	4	088	x<>y	142	SQRT	196	g x^2	250	2
035	CHS	089	GTO 268	143	g x^2	197	ENTER	251	9
036	+	090	2	144	g x^2	198	ENTER	252	5
037	*	091	STO 1	145	1/x	199	ENTER	253	7
038	3	092	Rv	146	1	200	.	254	7
039	.	093	g x^2	147	-	201	0	255	9
040	2	094	SQRT	148	SQRT	202	7	256	5
041	8	095	CHS	149	GTO 156	203	8	257	1
042	1	096	9	150	9	204	4	258	*
043	8	097	0	151	0	205	CHS	259	RCL 2
044	3	098	+	152	GTO 268	206	*	260	+
045	7	099	GTO 004	153	x<>y	207	.	261	RCL 1
046	5	100	STO 4	154	STO 4	208	1	262	g x=0
047	8	101	x<>y	155	x<>y	209	1	263	g x<>y
048	1	102	STO 3	156	ENTER	210	0	264	g x<>y
049	EEX	103	1	157	g x^2	211	3	265	-
050	8	104	STO 1	158	SQRT	212	5	266	RCL 0
051	CHS	105	RCL 4	159	g x=0	213	1	267	*
052	-	106	GTO 007	160	GTO 268	214	+	268	RCL 4
053	*	107	CLx	161	/	215	*	269	x<>y
054	5	108	STO 1	162	STO 0	216	.	270	GTO 000

SIN:	R/S		       (-90  <= x <=  90)
COS: 	GTO 090 R/S	       (-180 <= x <= 180)
TAN: 	GTO 100 R/S            (-90  <= x <=  90)
ASIN:	GTO 119 R/S            (-1   <= x <=   1)
ACOS: 	GTO 137 R/S	       ( 0   <= x <=   1) (just a program limitation!)
ATAN: 	GTO 153 R/S     (-9.99...E49 <= x <= 9.99...E49)

```

Hi Gerson, yes it looks like it will indeed run on the new 12c pt. The new one is not 5 times faster than the golden one ;-) But its accuracy may surprise you as it seems to have 12 sig. digits under the hood. 3 [1/x] shows 0.333333333 but then if we remove 6 of the 3s with .333333 [-] and multiply by E6 we see 0.333333000 - another 6 3s.
Cheers,
Tony

Hi Tony,

Thanks for the good news! When I was adjusting the MiniMax coefficients for the arctangent
function (the lowest power coefficients don't require so many significant figures), I considered
1/3 as 0.333333333333 (that's the constant in line 239) in my test spreadsheet. I correctly
guessed the 12C Platinum might have some extra guarding digits. By the way, that constant
should be 0.333333333089303 or 0.3333333331 to ten places but I wouldn't write it this way
just because of a '1' in the leftmost position. So I used 1/3 to 12 places and adjusted the
other constants with help of a spreadsheet and a graphics.

Using the constants explicitly in the program have significantly slowed down the execution time
as more steps have to be run. The constants could have been stores in registers, but then an
initialization routine would have been needed to avoid having to enter them by hand. Anyway, I
haven't calculated whether there would have been free registers left since the program uses
five registers already. In short, the gain in speed obtained by using only three coefficients
in the sine aproximation and only four in the arctangent approximating is lost when the constants
are built into the program. But the easy of use may compensate for this. Notice that the constants
beginning in lines 54 and 247 are pi/540 and 180/pi, respectively.

Reading again my post, I realized the example I provided was out of context. What I meant is that,
calculations like the following are easily done, since the latest computation is saved on the stack:

((sin(60) + tan(30)) * 6/5) ^ 2 :

60 R/S 30 GTO 100 R/S + 6 * 5 / g x^2 => 3.000000001

Thanks again for your remarks.

Cheers,

Gerson.

Correction:

Checking again my test spreadsheet, I discovered I had approximated 1/3 to only 10 significant figures, although I had previously thought of using 12 digits. As a consequence, the '2' in line 236 should be a '3'. Anyway, '2' implies in a maximum absolute error of 5.15E-12 for arguments between 0 and 1, while '3' brings the maximum error down to 4.10E-12.

```
-------------------------------------------------------------
In the tables below, the HP-15C column shows results obtained
with the built-in HP-15 functions, all of them correct to 10
significant figures, whereas the 12C Platinum shows results
obtained with the equivalent program run on the HP-15C. According
to Tony observations, the results on the real Platinum should
vary slightly, hopefully for better. The HP-35 shows the results
obtained on a bugless HP-35 (version 3). Like the program, its
only angular mode was Degrees.

Sin(x):
x (deg) 	   HP-15C	12C Platinum	   HP-35
---------------------------------------------------------------
0.00000	0.0000000000	0.0000000000	0.0000000000
0.00001	1.745329252E-07	1.745329252E-07	1.745000000E-07
0.00011	1.919862177E-06	1.919862177E-06	1.919800000E-06
0.02200	3.839724260E-04	3.839724261E-04	3.839723910E-04
3.330000	5.808674960E-02	5.808674960E-02	5.808674960E-02
14.44000	0.2493660251	0.2493660251	0.2493660250
25.55000	0.4312985870	0.4312985869	0.4312985871
36.66000	0.5970652564	0.5970652561	0.5970652561
47.77000	0.7404527827	0.7404527825	0.7404527828
58.88000	0.8560867283	0.8560867282	0.8560867285
69.99000	0.9396329127	0.9396329129	0.9396329127
81.11000	0.9879868528	0.9879868528	0.9879868527
88.88000	0.9998089500	0.9998089502	0.9998089499
89.99000	0.9999999848	0.9999999850	0.9999999848
89.99990	1.0000000000	0.9999999998	1.0000000000
90.00000	1.0000000000	1.0000000000	1.0000000000
Tan(x):
x (deg)   	   HP-15C	12C Platinum	   HP-35
---------------------------------------------------------------
0.00000	0.0000000000	0.0000000000	0.0000000000
0.00001	1.745329252E-07	1.745329252E-07	1.745000000E-07
0.00011	1.919862177E-06	1.919862177E-06	1.919800000E-06
0.02200	3.839724543E-04	3.839724543E-04	3.839724542E-04
3.330000	5.818499267E-02	5.818499266E-02	5.818499260E-02
14.44000	0.2575006491	0.2575006491	0.2575006490
25.55000	0.4780471798	0.4780471797	0.4780471798
36.66000	0.7442915883	0.7442915881	0.7442915880
47.77000	1.101686578	1.101686577	1.101686578
58.88000	1.656411391	1.656411390	1.656411391
69.99000	2.745986117	2.745986118	2.745986119
81.11000	6.393166451	6.393166452	6.393166426
88.88000	51.15042993	51.15042993	51.15042860
89.99000	5729.577893	5729.577895	5729.569869
89.99990	572957.7951	572957.7950	573019.3057
90.00000	9.999999999E+99	Error    0	9.999999999E+99
ArcTan(x):
x   	   HP-15C	12C Platinum	   HP-35
---------------------------------------------------------------
0.00000		0.0000000000	0.0000000000	0.0000000000
0.00011		6.302535721E-03	6.302535723E-03	6.302535688E-03
0.15500		8.810732986	8.810732984	8.810732984
0.26795		15.00004318	15.00004318	15.00004317
0.41421		22.49982578	22.49982579	22.49982579
0.57735		29.99998843	29.99998844	29.99998843
0.77700		37.84720677	37.84720678	37.84720676
0.88800		41.60507646	41.60507648	41.60507646
1.00000		45.00000000	45.00000000	45.00000000
1.22200		50.70548702	50.70548700	50.70548702
1.48880		56.11145723	56.11145722	56.11145722
2.11100		64.65265735	64.65265734	64.65265735
4.88800		78.43782359	78.43782359	78.43782360
7.55500		82.46000683	82.46000683	82.46000679
99.9990		89.42705557	89.42705557	89.42705555
3333333		89.99998281	89.99998281	89.99998281
```

Edited: 12 Nov 2005, 3:12 p.m.