 The Museum of HP Calculators

HP Articles Forum

Fifteen Digit Precision on the HP-32S

Posted by Palmer O. Hanson, Jr. on 18 Oct 2003, 12:43 a.m.

FIFTEEN DIGIT PRECISION ON THE HP-32S

We start with some arithmetic exercises using the statistical functions of the HP-32S:

Consider the numbers x = 1.000007

y = 1.000004

x^2 = 1.000014000049

y^2 = 1.000008000016

xy = 1.000011000028

where the squares and the products have thirteen significant digits. In calculators such as the HP-32S the squares and the product are rounded to twelve significant digits and displayed as 1.00001400005, 1.00000800002 and 1.00001100003. The rounding process essentially adds the values of 1E-12, 4E-12 and 2E-12 to the exact values to get the rounded values. Perform the following sequence from the keyboard of an HP-32S:

CLSUM clears the statistical registers 1.000004 ENTER 1.000007 SUM- LAST x SUM+

Use the STAT function to view the summation registers and see

SUMx = 0 SUMy = 0 SUMx^2 = -1.E-12 SUMy^2 = -4.E-12 SUMxy = -2.E-12

where the sums in x^2, y^2 and xy contain the negatives of the values which are added during rounding of the squares and product. Let's try another arithmetic exercise using the statistical functions:

Consider the numbers x = 111,111

y = 1,111,111,111

x^2 = 12,345,654,321

y^2 = 1,234,567,900,987,654,321

xy = 123,456,666,654,321

where in the HP-32S the squares and the product become

x^2 = 12,345,654,321

y^2 = 1.23456790099E18 displayed as 1.2345679E18

xy = 1.23456666654E14 displayed as 1.23456667E14

To see the actual twelve digit mantissas you can use the SHOW function. Perform the following sequence from the keyboard:

CLSUM clears the statistical registers 1,111,111,111 ENTER 1,111,111,111 to y 111,111 111,111 to x SUM-

where we expect the negatives of the rounded values to appear in those registers and do; for example for the square y^2, perform the sequence

STAT SUM y^2

and see -1.2345679E18 in the display with a mantissa of -123456790099 with the SHOW function. For the product xy, perform the the sequence

STAT SUM xy

and see -1.23456667E14 in the display and a mantissa of -123456666654 with the SHOW function.

Now, perform the following sequence which would be expected to remove the entered values from the statistical registers such that the values for SUMx, SUMy, SUMx^2, SUMy^2 and SUMxy should be zeroes:

1,111,111,111 ENTER 111,111 SUM+

SUMx^2 = 0, but

SUMy^2 = -2,350,000

SUMxy = 321

The result in SUMy^2 can be obtained by subtracting a value for y^2 which uses a rounded twelve digit mantissa from a value which uses a truncated (not rounded) fifteen digit mantissa; that is,

1,234,567,900,987,650,000 the fifteen digit truncated value of y^2 - 1,234,567,900,990,000,000 the twelve digit rounded value of y^2 = - 2,350,000

The result in SUMxy can be obtained by subtracting a value for xy which uses a rounded twelve digit mantissa from the actual fifteen digit value of xy; that is,

123,456,666,654,321 the fifteen digit value of xy - 123,456,666,654,000 the twelve digit rounded value of xy = 321

I obtain the same results with my HP-10B. These results are compatible with what was described as "... a tricky property of the SUM- and SUM+ keys whereby certain calculations can be carried out to 13 significant digits before being rounded back to 10 ..." in a footnote on page 208 of the HP-15C Advanced Functions Handbook, but adjusted for the 12 digit mantissas in the HP-32S and HP-10B. I do not get similar effects with older HP calculators such as the HP-33C, HP-67 and HP-80.

Pages 205-211 of the HP-15C Advanced Functions Handbook proposes eight cases for evaluating the ability of a quadratic program to solve difficult cases. It presents a single precision program for the HP-15C which can obtain correct results for only three of the eight cases. It also presents a program which uses the "tricky properties" in a double precision routine which carries twenty digits during the calculation of the discriminant. That program obtains correct results for all eight cases. It uses eleven data registers and is quite slow. An equivalent program on my HP-41C runs for as much as ten seconds to obtain a solution. In 1991 I wrote a single precision program for the TI-59 which uses truncated thirteen digit mantissas as opposed to the rounded ten digit mantissas used with the HP-11, HP-15 and HP-41. My TI-59 program obtained correct results for seven of the eight cases. It failed for the seventh case where the discriminant is the single digit difference between two twenty digit numbers. That program and similar programs for the TI-74, TI-81 and Casio fx-7000G are described on pages 8-13 of the Volume 14 Number 3 issue of TI PPC Notes.

The four cases which a single precision TI-59 program solves correctly but a single precision HP-41C program solves incorrectly (cases 4,5,6 and 8) all involve discriminants which are calculated as the difference between two numbers of 11 to 13 significant digits. Using the insight into the "tricky properties" of the SUM+ and SUM- functions derived from the numerical exercises similar to those above I wrote an HP-41 program which carries 13 significant digits during the calculation of the discriminant. That program yielded correct solutions to seven of the eight cases, used fewer registers and used less run time than the double precision program. The HP-41 program is documented in a 23 July 2003 entry in Archive 13 of the HP Forum with the title “Update: 13 Digit Precision on the HP-15C”.

A similar program for the HP-32S follows which will solve quadratics with discriminants which are calculated as the difference between two numbers of up to 15 significant digits. It follows the convention in the HP-15C Advanced Functions Handbook where the quadratic is defined as c - 2bx + ax^2 = 0 and the discriminant is calculated as d = b^2 - ac . That definition reduces the size of the two parts of the discriminant by a factor of four. The program calculates the terms of the discriminant in stages. First, the 3 least significant digits of the ac term are accumulated in statistics register SUMxy using the "tricky properties". That value is recalled and stored in the stack. Then the 3 least significant digits of the b^2 term are accumulated in statistics register SUMy^2 using the "tricky properties". Finally, the 10 most significant digits of b^2 and ac are calculated in the normal manner and combined before the smaller corrections for the least significant parts are applied. The program uses five data registers A through E. The user solves by entering the constants of the quadratic in response to prompts from the INPUT command and running the program. For real roots the program stops with one root in the display. The second real root is displayed by pressing x<>y. If the solution is complex Flag 0 is set. The program stops with the real part in the display. The imaginary root is displayed by pressing x<>y where + and - signs for the imaginary part are implied. The run time is less than one second. The program listing is:.

Q01 LBL Q Q02 CF 0 Q03 INPUT C Q04 INPUT B Q05 INPUT A Q06 CLSUM Q07 RCL C Q08 SUM+ Q09 LASTx Q10 SUM- Q11 SUMxy Q12 CLSUM Q13 RCL B Q14 SUM- Q15 LASTx Q16 SUM+ Q17 LASTx Q18 x^2 Q19 RCL A Q20 RCL× C Q21 - Q22 SUMx^2 Q23 + Q24 + Q25 x<0? Q26 GTO D Q27 SQRT Q28 RCL B Q29 ABS Q30 ENTER Q31 ÷ Q32 × Q33 STO E Q34 RCL+ B Q35 STO D Q36 RCL÷ A Q37 RCL D Q38 xNE0? x is not equal to zero Q39 GTO C Q40 CLx Q41 STOP C01 LBL C C02 RCL C C03 x<>y C04 ÷ C05 STOP D01 LBL D D02 SF 0 D03 +/- D04 SQRT D05 RCL÷ A D06 RCL B D07 RCL÷ A D08 STOP

A quadratic solver for the HP-32S which does not use the so-called “tricky properties” can still solve cases 4, 5 and 6 from the HP-15C Advanced Functions Handbook because those cases involve discriminants which are the difference between 11 significant digits. The reader can verify that if he must by deleting steps Q22 through Q24 in the program above. The 12 digit quadratic solver stumbles just a bit with case 8 in which the discriminant is the difference between the values 12,345,765,432.25 - 12,193,329,370 = 152,436,062.25 and 0.05 of the difference is lost due to the 12 digit limitation. That loss of 0.05 in the discriminant changes one root from the correct value of 123,458 to 123,457.999998 and the other root from the correct value of 98,765 to 98,765.0000016. The complete program above solves case 8 correctly. I also devised two additional cases which require the full fifteen significant digits. Those two cases will not be solved correctly by a TI-59 single precision program or by a thirteen digit HP-41 program which incorporates the “tricky properties”. Details for each of the test cases are included in the Appendix below.

APPENDIX - THE TEST CASE DETAILS

The quadratic equation used is ax^2 - 2bx + c = 0 for which the discriminant is d = b^2 - ac . Details are presented for cases 4 through 8 from the HP-15C Advanced Functions Handbook and for two additional cases which require a 15 digit capability.

Case 4:

a = 654,323 b = 654,322 c = 654,321

d = (654,322)^2 - (654,323 x 654,21)

= 428,137,279,684 - 428,137,79,683 = 1

R1 = 1 R2 = 0.999996943...

Case 5:

a = 11,713 b = 735,246 c = 46,152,709

d = (735,246)^2 - (11,713 x 46,152,709

= 540,586,680,516 - 540,586,680,517 = -1

Re = 62.77179203... ; Im = 8.5375E-05

Case 6:

a = 80,841 b = 987,644 c = 12,066,163

d = (987,644)^2 - (80,841 x 12,066,163)

= 975,440,670,736 - 975,440,683,083 = - 12,347

Re = 12.21711755... ; Im = 0.001374514...

Case 7:

This case, which involves calculating the discriminant as the difference between two 20 digit values can be solved with the double precision program on pages 208-210 of thr HP-15C Advanced Functions Handbook or by an equivalent program for the HP-41 which appears in my paper on the 13 digit capability of the HP-15C and HP-41.

a = 4,877,361,379 b = 4,877,262,613 c = 4,877,163,849

d = (4,877,262,613)2 - (4,877,361,379 x 4,877,163,849)

= 23,787,690,596,167,587,769 - 23,787,690,596,167,587,771 = -2

Re = 0.999979750 ; Im = 2.8995463E-10

Case 8:

a = 1 b = 111,111.5 c = 12,193,329,370

d = (111,111.5)2 - (1 x 12,193,329,370)

= 12,345,765,432.25 - 12,193,329,370 = 152,436,062.25

R1 = 123,458 ; R2 = 98765

The following additional test case is similar to case 4 from the HP-15C Advanced Functions Handbook. It yields a two digit difference between two fifteen digit numbers in the discriminant calculation. The positive value of the difference makes the roots real and unqual. Calculators such as (1) the HP-41 which typically retain only ten digits, (2) the HP-32S which typically retain only twelve digits, (3) the HP-41 programmed to use the “tricky properties”, and the TI-59 which typically retain only thirteen digits will all calculate the discriminant as zero and the two real roots will be erroneously found to be real and equal.

a = 11,111,119 b = 11,111,111 c = 11,111,103

d = (11,111,111)^2 - (11,111,119 x 11,111,103) =

= 123,456,787,654,321 - 123,456,787,257 = 64

R1 = 1 ; R2 = 0.999999280001

This second additional test case is similar to case 5 from the HP-15C Advanced Functions Handbook. It yields a two digit difference between two 15 digit numbers in the discriminant calculation. The negative value makes the roots complex with Re = b/a and Im = square root of d divided by a but if fewer than fourteen digits are retained due to calculator limitations then the discriminant will be calculated as zero and an incorrect answer of two equal real roots will result.

a = 8,441,600 b = 11,111,111 c = 14,624,809

d = (11,111,111)^2 - (8,441,600 x 14,624,909)

= 123,456,787,654,321 - 123,456,77,654,400 = - 79

Re = 1.31623282316 Im = ± 7.19999489E-7