Re: Bug with extended type?
"Felipe Rezek Mohallem" <[email protected]>
| Newsgroups | gmane.comp.lang.delphi.programming |
|---|---|
| Message-ID | <[email protected]> |
// try treating the number as string; class function TmxcUtil.ConvertVersionAsString(AMajorVersion, AMinorVersion: Integer) : Extended; begin Result := intToStr ( AMajorVersion ) + '.' + inttoStr ( AMinorVersion ); end; if ConvertVersionAsString(1, 20) >= '1.20' then ShowMessage ( 'YOU''LL GET HERE' ); // Best regards, // Felipe ----- Original Message ----- From: michael_grimard To: [email protected] Sent: Thursday, July 31, 2003 6:25 PM Subject: [Delphi] Bug with extended type? Hi, I have a function in a shared utility that I use to convert the major version and minor version to an extended type. class function TmxcUtil.ConvertVersionAsExtended(AMajorVersion, AMinorVersion: Integer) : Extended; begin Result := AMajorVersion + AMinorVersion/100 end; If I call with ConvertVersionAsExtended(1, 20), it should return me with 1.2. The version controls what the program can read from a file. The file can change between versions, so I need to check its version to know what I can read. The problem is that the comparison doesn't always work... if ConvertVersionAsExtended(1, 20) >= 1.20 then Read; // <-- I don't go here!!! I am suprised that ConvertVersionAsExtended(1, 20) returns 1.19999999999999996 instead of 1.2, since it can (assign 1.2 in an extended variable and check with the debugger, you will see that the value of the variable is still 1.2). I made a sample test project that called my function with the same parameter and that time, ConvertVersionAsExtended(1, 20) returns 1.2 as I expected it. How can that happened? I check the generated code with the debugger and the code generated for the same function in my two projects is different. So, my guess is that with my real project, the compiler doesn't use and extended type as supposed, but it uses a double instead, but in my test project, the compiler make the computation with extended variables. To prove that, I put the result returned by ConvertVersionAsExtended (1, 20) in a variable of type double and the variable is equal to 1.19999999999999996. So the extended variable that is returned by my function, in fact has the precision of a double?!? I placed all my variables in my function in new variables of extended type before doing the computation and the result is still the same... Anyone has ever seen something like this? I'm using Delphi 5 Pro. Thanks, Michael 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/