RE: Really strange problem, for very bright people
"Stephen Wood" <[email protected]> Fri, 8 Aug 2003 21:57:32 +0200
| Newsgroups | gmane.comp.lang.delphi.programming |
|---|---|
| Message-ID | <[email protected]> |
I understand that clearly, but what I'm failing to understand is how the following occurs... 1.035 * 4.32765 * 1.673 gives different answers to 1.673 * 1.035 * 4.32765 and 4.32765 * 1.673 * 1.035 They are the same numbers, just in a different sequence.... (Please note, these are not the numbers in my original equation, I've just written some very simplified numbers to illustrate the problem) The only thing I can think of, is that the order of the calculation, and therefore the order of precision loss, has a different outcome on the final answer.... Very strange... Anyway, thanks for all the help... -----Original Message----- From: jimdelilah [mailto:[email protected]] Sent: 08 August 2003 17:24 To: [email protected] Subject: Re: [Delphi] Really strange problem, for very bright people This may or may not help you understand. Try this and see what value is in vCalc_e2 when the code executes. var vCalc_e2 : Extended; begin vCalc_e2 := 239.752763879; // line 1 if (vCalc_e2 = 0) Then // line 2 ShowMessage(' equals 0 '); end you will see (at line 2)that vCalc_e2 will be 239.75276388. vCalc_e2 := 239.752763879; // line 1 vCalc_e2 = 239.75276388; This is because there is a *huge* set of numbers that cannot be represented in 8 or 10 bytes of data. It is kinda like trying to draw a rainbow with a box of 10 crayons. Sure you can get someting close, but under close exanimation you will see that the resolution is poor. ------------------------ 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/