![]() |
100-99.99-0.01 in a spreadsheet - Printable Version +- HP Forums (https://archived.hpcalc.org/museumforum) +-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html) +--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html) +--- Thread: 100-99.99-0.01 in a spreadsheet (/thread-107533.html) |
100-99.99-0.01 in a spreadsheet - Karl Schneider - 02-07-2007 All -- Digging through some old threads, I found one from late 2002 in which a contributor pointed out that the formula 100.00-99.99-0.01 would equal not zero, but 5.1156995306556 x 10-15 in a Microsoft Excel spreadsheet cell. Excel 2003 and Quattro Pro 12 (2004) return this result, which is due to roundoff error in floating-point calculations, as the first responder stated. In this case, IEEE 64-bit double-precision values are apparently used. The thread: http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/archv009.cgi?read=24977 The example illustrates an advantage of binary-coded decimal (BCD) -- exactitude eliminates the need for rounding and tolerance-checking. It's probably also why the HP-30S, which uses 80-bit floating-point representations, performs rounding to achieve "pleasing" results, which are not always strictly correct. Just as an exercise of curiosity, here are the computational steps in the floating-point calculation of 100.00-99.99-0.01: -- KS
Edited: 10 Feb 2007, 5:01 p.m. after one or more responses were posted
Re: 100-99.99-0.01 in a spreadsheet - hugh steers - 02-07-2007 here's my excel example, =IF(4.6-.2-.2-.2-4=0,"YES","NO") unfortunately, this is the case for IEEE-754 binary. you always get the same answer 4.6-.2-.2-.4-4 = -8.8817841970013e-016
it's one reason why i've changed hplua to now use an underlying decimal system.
more floating-point math in a spreadsheet - Karl Schneider - 02-07-2007 Hi, Hugh -- That's an even more curious example! While 100 and 0.01 are 13 orders of base-2 magnitude apart, 4.6 and 0.2 are only 5 orders of base-2 magnitude apart. Of course, there are four subtractions involved in total, instead of two. MS Excel 2003 computes zero as the result of the formula "=4.6-.2-.2-.2-4.0", but not if the expression is within parentheses, such as
=IF(4.6-.2-.2-.2-4=0,"YES","NO")
How can ya trust that? Quattro Pro seems to be a bit more consistent with results in that respect. However, I never warmed to using spreadsheet programs for straightforward calculations of limited volume -- too much frustration. -- KS
Re: 100-99.99-0.01 in a spreadsheet - Garth Wilson - 02-08-2007 Quote:This is a little O.T., but it looks like you're using the "E" incorrectly. I think you mean 5.1156995306556E-15. 1,000 = 1E3 = 10^3 = 10E2. "E" already means "times ten to the ___ power," so to say "x 10E__" puts you off by a power of ten. Also, 2E0=2, 2E1=20, 2E2=200, etc. Some engineering students and technicians at a company I did some consulting for years ago called me up with some simple calculations where things weren't coming out right. They had the presence of mind to know their results were way off, but they couldn't figure out why. This "E" thing is what messed them up. Re: more floating-point math in a spreadsheet - Gunnar Degnbol - 02-08-2007 Try =(0.3-0.1-0.1-0.1). I get -2.77556E-17. The reason for Excel's odd behavior is described in William Kahan's paper How Futile are Mindless Assessments of Roundoff in Floating-Point Computation ?:
Quote: He recommends they re-design Excel to use decimal arithmetic:
Quote:
Note that the WYSIWYG principle is lost not just when using binary arithmetic, but also when using hidden digits as the TIs do. Apparent precision is gained at the cost of predictability.
"E" notation - Karl Schneider - 02-08-2007 Hi, Garth -- Yes, you are correct -- I should stick with orthodox notation to prevent any possible confusion. It's just that "5.1156995306556 x 10E-15" looked better than the cluttered "5.1156995306556 x 10^(-15) or the run-together "5.1156995306556E-15" I was too lazy to superscript each value: "5.1156995306556 x 10-15 which can also be easily corrupted if responders quote without manually restoring the formatting.
-- KS
Re: more floating-point math in a spreadsheet - Karl Schneider - 02-09-2007 Gunnar -- Thank you for the link and response. This particular article by Kahan is fairly new (just more than a year old), and I had not seen it before. I didn't look at the date until I saw the quote from the article, "What's in your spreadsheet?" This is a twist on the catchphrase of a contemporary US television advertising campaign for a credit card: "What's in your wallet?" Professor Kahan really ought to be more concise; this article runs 56 pages. Section 2 of the article describes the strange behavior of MS Excel 2000, which probably hasn't changed in Excel 2003, and perhaps not even in the latest version. Section 5 tabulates "J-M. Muller’s Recurrence": xn = 5 – 2/(1 + (5/3)n) for which practically any BCD calculator gives accurate and best-possible results to the limits of its display, to n = 75 and beyond, long after the results from software utilizing floating-point math with 64-bit and 53-bit mantissas have diverged from the realm of numerical correctness. -- KS
Edited: 10 Feb 2007, 5:04 p.m.
Re: "E" notation - Rodger Rosenbaum - 02-09-2007 Quote: What's wrong with that? That's just how it looks or our beloved HP calculators. As long as we're picking on you, I would point that some would call these:
Quote:
"binary" points, not decimal points.
Re: "E" notation - Karl Schneider - 02-09-2007 Hi, Roger --
Quote: True, but it's a shorthand notation -- blank-free by necessity -- developed to represent "extreme" numbers within limited displays. Another problem with superscripting using preformatting is that the superscripted numbers look small. Clarifications will be applied to my original post.
-- KS
Re: "E" notation - Rodger Rosenbaum - 02-10-2007 Quote: Why is it "blank-free" by necessity? It wasn't developed to represent numbers within limited displays as far as I know. The notation has been used at least since Fortran when outputs were printed on 135 column wide printers. There was no space limitation. Calculators inherited the notation from those early computer languages. The calculators with truly limited display space, such as the HP15 and HP41 didn't even have an "E"; they had a space. The HP71's "PRINT USING" statement allows one to put several spaces before the "E", so space limitations aren't involved. But the default is the old Fortran style, 12.3456E78. Space limitations aren't a problem in the HP28, HP48, etc., but again the default is the Fortran notation. So, I don't think space limitations had anything to do with its development; rather it was the lack of superscripts on the printers of the time. -------------------------------- In your first post in this thread where your revision now says: "base-2 representation with aligned radix" I think you should say: "base-2 representation with aligned radix points" See: http://en.wikipedia.org/wiki/Radix http://en.wikipedia.org/wiki/Radix_point
Re: "E" notation and radix point - Karl Schneider - 02-10-2007 Quote: That depends on the application. I was referring primarily to the entry of exponentiated numbers in computer-language code, not the display or printing of them. If a space were inserted betewen the mantissa and the "E" (or "D" for double precision), the Fortran compiler would unsuccessfully try to parse the number into an exponent and a variable. I'm an old Fortran guy (too?), and I remember offhand that 132 characters was the standard limit for line-printer output.
Quote: More specifically, the exponents on these models were right-justified to provide one or more spaces as the display setting permitted. Of course, with spaces, the "E" isn't even necessary, and would waste a valuable display position. I prefer the spaces to the full-size "E" used in the HP-20S, HP-21S, HP-32S, and others. Apparently, so did other people at H-P; the HP-32SII uses a reduced-size "E" (as well as an elevated "-" for negative exponents) in the display to help distinguish exponentiated numbers. This was more important in the HP-32SII, with its Equation capabilities that utilized variables denoted by single capital letters. That's attention to detail. BTW, when I stated "limited displays", I was also referring to lack of sub- and superscripting as well as length of display windows.
Quote: Right you are. I knew of "radix" only from the HP-42S RDX functions which set the style of radix point. By golly, there's a Wikipedia entry for everything! -- KS
Re: "E" notation and radix point - Rodger Rosenbaum - 02-10-2007 Quote: Too bad you didn't say that. Then my comments could have been relevant to your intent.
Quote: This isn't "necessity"; this is convention. The parser could easily accept free-form input, including spaces, and use comma, semicolon or CRLF as the terminator. I don't have any Fortran manuals anymore, and I don't know what free-form capability may have been available in any particular Fortran compiler. But I like to refer to the HP71's BASIC because it is one of the most capable machines I've ever seen as far as input/output formatting goes. It has a built-in free-form input capability for HPIL input. For ordinary input, numbers can be input as strings and there are string functions that allow the user to remove superfluous spaces, or any other character, and then convert to a number in a variable with the VAL function. The user can do their own free-form input with this capability. Therefore, I don't agree that the "E" format is "blank-free by necessity".
Quote: Must have been a different printer.
Quote: Why would an "E" in an exponential format number waste a display position, but a space wouldn't? Wouldn't the "E" be in the same position as the space, occupying one character position, just as the space does?
Quote: I prefer the "E" of whatever size. The space is ok on a small size calculator display like the HP-41, but if it is printed on paper, the space rather than "E" will make it look like two non-exponential numbers rather than one "E" format number, e.g.: 12.345E26 with spaces becomes 12.345 26 I like to have the same format on the calculator display as when it's printed on paper. I'm used to the "E" format on both paper and a calculator display; it looks the same both places. My TI-86 uses a small size "E" and elevated "-"; it's ok. Maybe those "other people" at H-P are an invasion force from TI (or some Japanese manufacturer of calculators). :-)
Quote: What you said earlier was that the "E" notation was "...developed to represent "extreme" numbers within limited displays." To speak of "displays" like that sure sounds like you were referring to something like a calculator display such as found on a hand-held calculator. When the "E" format was developed, there weren't any such "displays"; there was printed output. There was no "length" limitation on printed "E" format numbers such as there is on a calculator display. I said in my reply:
Quote: To be perfectly clear, I think that to the extent you were suggesting that length limitations had anything to do with the development of the "E" format, you were mistaken. I think it was solely the lack of superscripts on the printers of the time. On that point, you and I are in agreement. As far as the use of the compact "E" format nowadays, it seems that you don't like it, but I do; I'm used to it. We all have our preferences.
Re: 100-99.99-0.01 in a spreadsheet - Rodger Rosenbaum - 02-10-2007 A while back when the HP30S came out, there was some discussion about what its internal workings were. I posted a long item on the newsgroup. You can use Microsoft's BASIC to play around with binary representations. Here is what I posted:
Quote: Other numbers in the Excel spreadsheet - unspellable - 02-12-2007 Try filling a short column with -5, -4,-3,-2,-1, 0, 1, 2, 3, 4, 5. Find the standard deviation = 3.02765... So far so good. Now if you have an older version, up to about '98 and I think 2000 as well, try this with 14,999,999,998 through 15,000,000,005. The correct answer should be the same but the spreadsheet will come up with nonsense. This not due to the internal arithmetic so much as it is due to poor choice of algorithm. The algorithm is mathematically correct but when doing numerical computation all the significant data is rounded off.
BTW: This came up as a real world problem. Whipped out my HP-48SX and it had no trouble with this calculation.
Re: Other numbers in the Excel spreadsheet - bill platt - 02-12-2007 I get 3.317
Standard deviation calculation in Excel - Karl Schneider - 02-12-2007 Quote: This looks like the sample standard deviation for the first ten values or the last ten. When you copied a range of cells into the formula, you may have missed one. The correct population standard deviation is 3.16228 The correct sample standard deviation is 3.31662 MS Excel 2003 gives the correct answers with 14,999,999,995 through 15,000,000,005. Quattro Pro v12 calculates zero as either standard deviation for the large input data, as do calculators that use the summation method, instead of retaining each input datum and first calculating the mean therefrom (e.g., HP-17B/II, HP-27S, HP-28/48/49/50). This was discussed in a thread from several years ago; Tom Sherman's post elaborated in detail. http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/archv014.cgi?read=53787#53787
I'm somewhat surprised that not all modern spreadsheet software can give the correct answer to this problem. The PC-based programs are already storing all the input data, and there's no shortage of processing power. -- KS
Edited: 13 Feb 2007, 8:59 p.m.
Re: Standard deviation calculation in Excel - unspellable - 02-14-2007 I probably mistyped something. But the main point is that Excel versions up through 98 or 2000 give totally bogus answers due to rounding off the significant data. It's more evidence that Micro Soft's primary objective is a new version with new window dressing rather than actually making software that works. Another cute trick is finding the square root of -1. I get: 6.12303176911189E-017+i Come on, be serious! A rounding error for sqrt(-1)?
This was in Excel 2003 although I think all previous versions do the same.
Re: Standard deviation calculation in Excel - Ken Shaw - 02-19-2007 MS Excel 2002 (version 10.2614.2625) failed this test with: Sample std dev = 228.973360895978 Population std dev = 186.181818181818
Stunning.
|