Really strange problem, for very bright people
Stephen Wood <[email protected]> Fri, 8 Aug 2003 09:00:17 +0200
| Newsgroups | gmane.comp.lang.delphi.programming |
|---|---|
| Message-ID | <74D67F1862B5D711A9CA00B0D0D1F4C981AB63@dhexchange3.discoveryhealth.co.za> |
Hi all, I'm looking for some really bright people to help with this one, because in my entire life, I've never seen something as strange as this. 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 Now do this.... vCalc := (4.328247 * ( 33660 / 1000 ) * 1.06 * 1 * 1 * 1.5 * 1.035 ) - ( 4.328247 * 1.06 * 1.5 * 1 * ( 33660 / 1000 ) * 1.035 ); You'll notice that I just moved the 4.328247 and 1.06 to the front of the of the second brackets and you get an answer of 1.3877787808e-17 Now try this... vCalc := (4.328247 * ( 33660 / 1000 ) * 1.06 * 1 * 1 * 1.5 * 1.035 ) - ( 4.328247 * 1.06 * 1.035 * 1.5 * 1 * ( 33660 / 1000 ) ); All I've done now is move the 1.035 after the 1.06 in the second brackets and I get an answer of 0 (which is actually the correct answer, which we expected, and which Excel gives us as well) Just moving the value around in a multiplication calculation produces different results....the different results are consistent with single, double and extended types, but with comp and currency types, the calculation is correct every time.... Can anyone explain this? Thanks Steve [Non-text portions of this message have been removed] ------------------------ 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/