The Museum of HP Calculators

HP Forum Archive 19

[ Return to Index | Top of Index ]

The peculiar arithmetic of the SmartCalc 300s
Message #1 Posted by Javier Goizueta on 27 May 2009, 4:48 a.m.

I've received my HP SmartCalc 300s and I'd like to share some findings about its arithmetic. This calculator shows 10 digits but keeps 16 digits of internal precision in its registers. So this machine should have impressive precision, right?

I'll do a little test that appeared on Fred Gruenberger's Computer Recreations in Scientific American, April, 1984 (I actually read it from the spanish "Investigación y Ciencia" in June 1984) The test consists in computing (1.0000001)^(2^27) by applying the square operation 27 times starting with 1.0000001. The correct answer is 674530.47074108455938....

First, to know what kind of precision we can expect we'll do some testing with a HP50G. The HP50G has 15 internal digits and we can operate with that precision using the XREAL library So let's try it:

  << 1.0000001 R~X 1 27 START XSQ NEXT >>
The result is 674530.467837207 with a percent error of 0.0000004305

But we can do better with 15 digits: the internal 15-digit arithmetic of the HP50G is truncated because it's not meant to be seen; we can operate with 15 rounded digits (or any other rounding/number of digits) using the LongFloat library

  << 1.0000001 R<-->F 1 27 START FSQ NEXT >>
Now the result is 674530.469940699 and the percent error is 0.0000001186

So now we know what to expect with so many digits of precision; let's try the SmartCalc. We'll use the LinearIO mode so that we operate numerically and not with the mini-CAS that MathIO uses.

If we type 1.0000001 and then [x^2] [=] 27 times we get: 674529.1123 with a percent error of 0.0002014 (that's like 468 times larger than the XREAL result which one less digit and truncating the results!!) That's even worse that what can be achieved with 13 digits (percent error of 0.00002264 with LongFloat).

How can this be? Well, I wasn't too suprised becaused I'd played with Casio calculators before.

The reason is that following Casio tradition, some weird rounding if done on the internal numbers, trying to hide the fact of a limited precision, so that for example 1-(4/3-1)*3 = 0 (which in a honest numerical calculator would reveal the internal precision.) This rounding makes errors unpredictable and much larger than they could be. Note also that these attempts are bound to fail: 1/9-(10/9-1) = 0 but (1/9 - 0.01 - (10/9-1) + 0.01 = 1E-16

The results of the HP300S in the 1.0000001 test can be explained by a special rounding of the result of arithmetic operations performed after normalization:

  • if the trailing 6 digits are less than 000050, they are rounded down to 000000.
  • if the trailing 4 digits are greater than 9949, the number is rounded up (so it ends in 0000)

You can see these rules in action here

     1E9 + 1.000050 - 1E9 = 1.00005
     1E9 + 1.000049 - 1E9 = 1
     1E9 + 0.100049 - 1E9 = 0.100049
     1E9 + 0.009950 - 1E9 = 0.01
     1E9 + 0.009949 - 1E9 = 0.009949  
     

Note that numbers typed in the calculator are truncated to 15 digits; if you need to enter a value with full 16 digits you must add a pair of numbers or do some other operation.

The special rounding explains all the intermediate results of the test, which are show here with full internal precision

  1.0000002
  1.0000004
  1.00000080000016
  1.00000160000096
  1.00000320000448
  1.0000064000192
  1.00001280007936
  1.000025600322562
  1.0000512013005
  1.000102405222573
  1.000204820931975
  1.000409683815564
  1.000819535471956
  1.001639742582301
  1.003282173920338
  1.006575120506319
  1.01319347322231
  1.026561014180287
  1.053827515834859
  1.110552433130669
  1.233326706732449
  1.521094765539508
  2.31372928575169
  5.353343207745025
  28.65828349990979
  821.2972131612017
  674529.1123463563
  

I've traced similar magic rounding in a Casio FX9960G (using an emulator) and in an old Casio FX750P. These machines have more complicated rounding rules and the results of the test are similarly poor. In the case of the FX750P we can operate either at the internal precision of 12 digits (using variables) or at the displayed precision of 10 digits. Due to the idiosincratic rounding the result of the test using 10 digits is more precise than with 12 digits!

It's a shame that the SmartCalc tries so hard to be smart. The result of computing 1-(4/3-1)*3 numerically should be 1E-15 showing that it is operating with limited precision. It should be 0 only if fractions or the MathIO mode are used, but the user should know the distinction between exact and approximate computations and be able to compute numerically with predictable results. The SmartCalc is very unreliable, with some results in accordance to its high internal precision and others randomly affected by large errors.


And now for something totally different: My HP300S has a sticker on the back "Prototype Not for Sale" I saw it after ripping the package and then noticed the sticker on it too:

Quote:
Prototype - Not For Sale. The unit and contents of this packaging are currently undergoing quality testing and verification and are subjected to changes. ...
I wonder if there's any difference with a production unit; my keyboard misses keystrokes quite often and the cover cannot be snapped on the back as the user manual suggests.

Anybody with a production 300S can tell about that?

Edited: 27 May 2009, 6:53 a.m.

      
Re: The peculiar arithmetic of the SmartCalc 300s
Message #2 Posted by hugh steers on 27 May 2009, 12:02 p.m.,
in response to message #1 by Javier Goizueta

this is very interesting. i am wondering if this rounding is actually to disguise the fact that the 300 works in binary internally rather than BCD.

I first noticed a new and weird kind of rounding in the 30s. This is the calculator that not many people liked because it was one of the first not really made by HP at all. afaik the 30s and 9g use binary math internally and perform some weirdo rounding to hide it.

i spend a while trying to figure this out, but i found the rounding not consistent. both these models work to approx 25 digits, but the effective accuracy is around 12 due to the fact that it will round at every stage.

is the 300s really a binary machine?

            
Re: The peculiar arithmetic of the SmartCalc 300s
Message #3 Posted by Javier Goizueta on 27 May 2009, 2:28 p.m.,
in response to message #2 by hugh steers

Quote:
is the 300s really a binary machine?

I don't think so. All the results reveal exactly 16 decimal digits. Also, the result of 1/9 - 0.001 - (10/9-1) + 0.001 is exactly 1E-16 which I find hard to explain in a binary machine.

      
Re: The peculiar arithmetic of the SmartCalc 300s
Message #4 Posted by Gerson W. Barbosa on 27 May 2009, 12:08 p.m.,
in response to message #1 by Javier Goizueta

Quote:
I'll do a little test that appeared on Fred Gruenberger's Computer Recreations in Scientific American, April, 1984 (I actually read it from the spanish "Investigación y Ciencia" in June 1984) The test consists in computing (1.0000001)^(2^27) by applying the square operation 27 times starting with 1.0000001.

Interesting article! I read it back then in the university library and I still keep a copy of it.

Quote:
The reason is that following Casio tradition, some weird rounding if done on the internal numbers, trying to hide the fact of a limited precision,

Roger Rosenbaum has shed some light on this subject in the following threads:

http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/archv016.cgi?read=103356

http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/archv016.cgi?read=103151

I just hope the HP SmartCalc 300s gives the right answer to expressions like '3979/LN((sqrt2+sqrt3)/sqrt3)'

Regards,

Gerson.

            
Re: The peculiar arithmetic of the SmartCalc 300s
Message #5 Posted by Javier Goizueta on 27 May 2009, 1:36 p.m.,
in response to message #4 by Gerson W. Barbosa

Quote:
I just hope the HP SmartCalc 300s gives the right answer to expressions like '3979/LN((sqrt2+sqrt3)/sqrt3)'

The result is 6666.000006 (internally it is 6666.000005835731 which I believe is the correct result rounded to 16 digits). The results look very good except when the special rounding is triggered.

Thank you for the links, I'll have a look at them.

      
Re: The peculiar arithmetic of the SmartCalc 300s
Message #6 Posted by Marcus von Cube, Germany on 28 May 2009, 2:51 a.m.,
in response to message #1 by Javier Goizueta

There was a recent discussion in the French MySilicium forum (this part is even in English). Some Casio BASIC machines have a means of turning the weird rounding behavior on and off via MODE 10 and MODE 11 commands.

Edited: 28 May 2009, 2:45 p.m.


[ Return to Index | Top of Index ]

Go back to the main exhibit hall