HP-33S trigonometric inaccuracy -- new findings Message #1 Posted by Karl Schneider on 10 Dec 2006, 1:18 a.m.
All --
Recently, Gerson Barbosa made me aware of a trigonometric-function bug in the HP-33S in this archived post:
http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/archv016.cgi?read=103065#103065
His example was the tangent of 89.999... degrees, but I've tried to get to the heart of the matter in that thread and subsequently.
It was opined in the thread that tan(x) might be computed using sin(x)/cos(x). Although not unreasonable, I doubt that it is correct, because timing tests using the following example program on the HP-32SII and HP-33S showed that computation of tangent is faster than that of sine and cosine, for values between 0 (noninclusive) and at least 85 degrees:
LBL L
30 (or other value)
TAN (or SIN or COS)
DSE L
GTO L
RTN
(Store an integer value in L -- say, 100 -- then XEQ L.)
Perhaps the tried-and-true CORDIC routines are still being used, in which tangent or cotangent is computed first, and then sine and cosine are calculated therefrom:
sin(x) = (+/-)tan(x) / sqrt[1 + tan2(x)]
cos(x) = (+/-)cot(x) / sqrt[1 + cot2(x)]
The above equations are printed in an article from the June 1977 Hewlett-Packard Journal, "Personal Calculator Algorithms II: Trigionometric Functions". (A scan of this article is in "77JUNAL2.PDF" from the MoHPC CD/DVD set.)
Here are some calculations to 12 significant digits using an angle of 0.0001 radians:
104 * tan(0.0001)
HP-32SII 1.00000000333
HP-33S 1.00000000330
actual 1.00000000333
105 * sin(0.0001)
HP-32SII 9.99999998333
HP-33S 9.99999998300
actual 9.99999998333
So, we can see that one significant digit is lost for the scaled tangent in the HP-33S, and two digits are lost for the scaled sine. The additional lost digit could be a result of the higher multiplier needed to reveal the last digit, or might be related to calculating sine from tangent.
My "actual" values came from the Windows XP Calculator, but one can easily confirm the results using Taylor series with terms less than the 15th significant digit truncated:
sin(x) = x - x3/3! + x5/5! - ...
cos(x) = 1 - x2/2! + x4/4! - ...
tan(x) = sin(x) / cos(x)
For x = 0.0001, the first two terms will suffice for 15 significant digits:
sin(0.0001) ~= 10-4 - 10-12/6
~= 0.0000999999998333
~= 9.99999998333 x 10-5
cos(0.0001) ~= 1 - 10-8/2
~= 0.9999999950000000
sin(0.0001)
tan(0.0001) = -----------
cos(0.0001)
10-4 - 10-12/6
~= -------------
1 - 10-8/2
Multiplying through by (1 + 10-8/2),
10-4 - 10-12/6 + 10-12/2 - 10-20/12
~= --------------------------------
1 - 10-16/4
Truncating the smallest terms and combining,
~= 10-4 + 10-12/3
~= 0.000100000000333
~= 1.00000000333 x 10-4
And there you have it -- the HP-32SII gave correct answers to 12 significant digits for sine and tangent with small arguments, but the HP-33S does not. Chalk up another for the "HP-33S bug list".
-- KS
Edited: 10 Dec 2006, 1:27 a.m.
|