RE: Really strange problem, for very bright people

Stephen Wood <[email protected]> Fri, 8 Aug 2003 14:44:43 +0200
Newsgroups gmane.comp.lang.delphi.programming
Message-ID <74D67F1862B5D711A9CA00B0D0D1F4C981AB6D@dhexchange3.discoveryhealth.co.za>
Thanks guys for the answers, I'm getting the picture, yet not fully
understanding it yet.....I'll get there though....

Thanks!!

-----Original Message-----
From: Toomas Piibe [mailto:[email protected]] 
Sent: Friday 08 August 2003 02:35
To: [email protected]
Subject: Re: [Delphi] Really strange problem, for very bright people


----- 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



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/ 



[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/