Re: Bug with extended type?

"Rory Daulton" <[email protected]>
Newsgroups gmane.comp.lang.delphi.programming
Message-ID <003d01c3582b$9ea30e30$6501a8c0@laptop>
Michael,

> but I know that floating point variables are not precise, but
> shouldn't they always have the same to represent the same value?
>
> 1.20 stored in a double variable should always be represented by
> 1.19999999999999996, no?
>
> If 1.20 is stored in an extended variable, why one time it is
> represented by 1.2 and the other time by 1.1999999999999996?

As I wrote,

>> That is the problem in working with floating-point types, the exact
values
>> you get are highly dependent on the calculations, their order, and the
type
>> of intermediate variables.

So the answer is, no, floating point variables do not always have the same
internal representation of the same value.  This topic is covered in detail
in any course or book in "Numeric Analysis," but just believe me that the
silliest things can change the exact value of a floating point variable.

Part of the problem is that it is *impossible* to store 1.20 exactly in a
binary floating point variable, since the denominator of the equivalent
fraction 6/5 is not a power of two.  Any assignment of 1.20 to a Double or
Extended variable involves an approximation, and this can be done in
different ways in different circumstances.  Even different versions of
Delphi do it in different ways.  The debugger does it in a different way
than the compiler.  And so on.  You should just accept it as a fact of life,
or it can drive you crazy.  It is informative to use the CPU and FPU views
of Delphi's debugger to see just what changes are made when in your code.

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 ---------------------~-->
Free shipping on all inkjet cartridge & refill kit orders to US & Canada. Low prices up to 80% off. We have your brand: HP, Epson, Lexmark & more.
http://www.c1tracking.com/l.asp?cid=5510
http://us.click.yahoo.com/GHXcIA/n.WGAA/ySSFAA/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/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.