Re: Really strange problem, for very bright people

"Rory Daulton" <[email protected]> Mon, 11 Aug 2003 07:33:34 -0400
Newsgroups gmane.comp.lang.delphi.programming
Message-ID <00c201c35ffc$66f70d50$6401a8c0@laptop>
Stephen,

> We have a calculation engine that does a whole whack of calculations...on
we
> picked up a bug with it. We then stripped down the calculation to bare
bones
> and were quite amazed at what we found....below is a code snippet to
explain
> what's happening...
>
> var
>   vCalc : extended;
>
> vCalc := (4.328247 * ( 33660 / 1000 ) * 1.06 * 1 * 1 * 1.5 * 1.035 ) - (
1.5
> * 1 * ( 33660 / 1000 ) * 4.328247 * 1.06 * 1.035 );
>
> This gives an answer of 2.7755575616e-17

I'll add one more comment to what has been said.  You are actually looking
at *two* problems.  The first is the approximation that happens in
multiplication and division and which is done differently if the calculation
order is changed.  You have read much on this already.

The second point is that your calculation subtracts two numbers that are
almost or exactly equal.  This has the effect of magnifying small errors
into relatively large errors.  One major technique in numeric analysis is to
avoid this kind of subtraction.

For example, the numbers 1.3333333333 and 1.3333333334 are almost identical,
and either can be used in most situations.  There are 10 significant digits
here.  But subtracting them gives 1e-10, which looks very different from
zero and has *no* significant digits.

Rory Daulton
[email protected]


---
[This E-mail scanned for viruses by Declude Virus and Nmax "Your MAXimum Connection!"]
[This E-mail scanned for spam by Declude JunkMail and Nmax "Your MAXimum Connection!"] 


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for Your HP, Epson, Canon or Lexmark
Printer at Myinks.com. Free s/h on orders $50 or more to the US & Canada. http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/l.m7sD/LIdGAA/qnsNAA/i7folB/TM
---------------------------------------------------------------------~->

CodeCoffer - new Delphi code protection Tool!
http://www.delphicollection.com/public/CodeCoffer.htm
---------------------------------------------------------------
Unsubscribe:[email protected]
List owner:[email protected]
--------------------------------------------------------------- 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/