Saturday, December 23, 2017

Decimal Floating Point in Scientific Calculators

Back in the 1980's when I first studied numerical analysis, different computers used different storage schemes for floating point arithmetic.  Although binary floating point was widespread, there were significant differences between the binary floating point systems on machines from different manufacturers.  IBM made things even more interesting with the hexadecimal (base-16) floating point used on the System-360/370 computers.  The IEEE-754 standard was just being developed.  The variety of floating point standards was a useful source of examples for teaching the basic concepts of floating point arithmetic.

Today, every computer in wide use, along with smartphones, tablets, and higher-end graphing calculators all use IEEE-754 binary floating point arithmetic.  There really aren't any other systems in widespread use (one recent exception is the use of 16 bit "half precision" in neural network computations.)

Inexpensive scientific calculators from Casio, HP, Sharp, and Texas Instruments are one exception to this trend.  These calculators typically use decimal floating point arithmetic.  It's nearly universal in these calculators to have an exponent range from 10 to the -99 power to 10 to the +99 power, with 10 significant digits displayed.

The 10 digit results shown on the display should be properly rounded.  You can check how rounding is done with

1.123456788 + 6E-10

which should round up to

1.123456789

and

1.123456788 + 5E-10

which might either round up (ending in "89") or round to nearest even (ending in "88".)  In practice, nearly every calculator I've seen rounds 5's up (R5UP in the table below.)

Often times, the calculator performs internal computations with more significant digits.  You can check this on a calculator by performing a calculation like

1.123456789+1.23456789E-10

and then subtracting

ANS-1.123456789

A result of 1.2E-10 indicates that the calculator maintains 12 digits internally.

If 15 digits were being kept internally, then you'd get back 1.2345E-10, or perhaps 1.2346E-10, depending on whether the calculator was properly rounding the fifteenth digit or truncating.

A feature that some newer calculators have is the ability to convert from decimals to nearby exact fractions with small numerators and denominators.  Typically, the user just presses a button to switch back and forth from decimal to fractional form. In the case of the Casio FX-115ES PLUS described in the table below, you can also get the answer in repeating decimal form with a bar over the repeating digits.  The Casio limits fractions to a total of 10 digits in the numerator and denominator.  The conversion to fractional form seems to be quite resistant to small round-off errors. 

The conversion to fractional form can be done by forming the continued fraction expansion of the decimal and truncating after a small number of terms in the expansion.

I grabbed the scientific calculators in my desk and ran the tests described above.  The results are shown in the following table. Here R5UP refers to conventional rounding with 5's rounded up, TRUNC refers to truncation with no rounding.  I'd appreciate information about any other scientific calculators that you might have in your desk drawer. 

8 comments:

  1. The TI-30XIIS displays some weird behavior that I can't explain:

    1.123456789+1.2345E-10-1.123456789=1.235E-10

    This is what I would expect from 14 digit arithmetic with R5UP rounding.

    5.0+1E-11-5.0=1E-11
    5.0+1E-12-5.0=0.0E+00

    Here, the intermediate results seem to have been rounded to 12 digits rather than 14 digits!

    Also,

    4.999999999 + 1.0E-10 - 4.999999999=1.0E-10
    4.999999999 + 1.0E-11 - 4.999999999=1.0E-11
    4.999999999 + 1.0E-12 - 4.999999999=0.0E+00

    This also seems to be rounded to 12 digits correctly.

    However,

    4.999999999 + 1.2345E-10 - 4.999999999 = 1.235E-10

    which again looks like 14 digit arithmetic.

    It appears that the TI calculator is capable of 14 digits, but either rounds results to 12 digits in some cases, or simply doesn't do the addition if the smaller term has 0's in the first 12 positions.

    ReplyDelete
  2. A bit more research shows that

    4.999999999 + 1.0E-12 - 4.999999 - 9.99E-7=1.0E-12

    This tells me that that the 1.0E-12 made it through the first addition correctly.

    This was all very mysterious, until I found the following quote:

    "If a and b are floating point numbers that differ by less than one unit in the second least significant digit of max(|a|, |b|), (i.e., one unit the thirteenth, base 10, significant digit), then a − b is set to zero."

    in a discussion of TI-83 rounding at

    http://people.ku.edu/~wzhuang/CAMseminar/CAM06Fall/DirtySecrets.pdf

    The document makes some suggestions about why this feature might have been added by TI that sound reasonable. It appears that the TI calculators in my collection all have this feature.

    Furthermore, the Casio FX-115ES PLUS that I tested has a similar feature,

    4.999999999 + 1.0E-12 - 4.999999999 = 1.0E-12
    4.999999999 + 1.0E-13 - 4.999999999 = 0.0E+00
    4.999999999 + 1.0E-13 - 4.999999 - 9.99E-7 = 1.0E-13

    ReplyDelete
  3. It is especially decent, though look into the tips during this home address. centimeters to inches

    ReplyDelete
  4. I like viewing web sites which comprehend the price of delivering the excellent useful resource free of charge. I truly adored reading your posting. Thank you! science

    ReplyDelete
  5. I feel very grateful that I read this. It is very helpful and very informative and I really learned a lot from it. calculator

    ReplyDelete
  6. I am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work. science

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. Unlike the other commenters, I'm an actual human being. Many thanks for this, and for the links! I have both a 36xPro and a 30XIIS, and I'm fascinated to see they're not just IEEE-754, though it makes sense, they're probably trying to keep their transistor count as low as possible.

    ReplyDelete