Re: Bug with extended type?
"Michael Grimard" <[email protected]>
| Newsgroups | gmane.comp.lang.delphi.programming |
|---|---|
| Message-ID | <[email protected]> |
thanks Rory, 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? It looks like to me a compiler problem, more than with my code... The same function with same parameters used in two different projects generates different result (and different code). I am not really good in assembler, but it seems that the size of data but on the stack is not the same. It might explain why one time I got the precision of a double and the other time, the precision of an extended. Anyway, my versions are always limited to two decimals, so now I check with ConvertVersionAsExtended(1, 20) >= (1.20 - 0.001) an it works. Michael ----- Original Message ----- From: Rory Daulton To: [email protected] Sent: Thursday, July 31, 2003 5:38 PM Subject: Re: [Delphi] Bug with extended type? Michael, > I have a function in a shared utility that I use to convert the > major version and minor version to an extended type. 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. The best thing is to avoid the floating point type. Just the day before yesterday I wrote a routine to get a number for the version of Windows currently running, and I wrote it to avoid floating point types. I stuffed the minor version number into the least significant byte of an integer, the major version into the next byte, and the ID (platform type) into the next byte. That is working well for me. If you must use floating point types such as Extended, never test for equality or for exact tests like ConvertVersionAsExtended(1, 20) >= 1.20 Instead, use something like ConvertVersionAsExtended(1, 20) >= 1.19995 Then, even if the result is slightly below 1.20 the test will work as you want. 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 ADVERTISEMENT 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 the Yahoo! Terms of Service. [Non-text portions of this message have been removed] ------------------------ 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/