Re: Really strange problem, for very bright people
"Toomas Piibe" <[email protected]> Fri, 8 Aug 2003 15:35:09 +0300
| Newsgroups | gmane.comp.lang.delphi.programming |
|---|---|
| Message-ID | <[email protected]> |
----- Original Message ----- From: "Stephen Wood" <[email protected]> > Thanks Jeff, > > What I can't understand is that the calculation actually works with the > other types (extended, double, etc) only if the order is changed, so > therefore rounding issues, and insignificant digits are not the problem, > because the calculation does work....but just in a different order. > It works in both cases. > > And secondly, how is a developer supposed to understand in what order to > write the calculations, unless the bug actually manifests itself? > It is not bug. It simply is how IEEE and Intel used to do floating point calculations. Floating point number are not exact numbers but approximation. Developer must know that and never use direct comparision of two floating point numbers. What happened in your calulations is something like that if integera are used floating point numbers . Say you calculate 5*(3/2)* 2 3/2 =1.5 => 2 5*2=10 10*2=20 but (2*5*3)/2 is calculated 2*5=10 -> 10*3=30 -> 30/2 =15 Problem is rounding of least significatn bit. > > And thirdly, this calculation is used many times with different input > parameters and calculates correctly, but it seems that the bug only happens > when "certain" input values are used....really really weird... > It always calculates correctly in viewpoint of digital floating point calculations, it almost never calculates exactly. It is not possible express 1/3 exactly. See: Numerical Accuracy 101 for Delphi Developers http://efd.home.mindspring.com/acc101.htm Pascal Floating-Point Page http://www.merlyn.demon.co.uk/pas-real.htm What Every Computer Scientist Should Know About Floating-Point Arithmetic http://docs.sun.com/source/806-3568/ncg_goldberg.html Long and not for everyone as its for computer scientists. Toomas ------------------------ 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/