Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Floating Point Exception

Status
Not open for further replies.

zifnabbe

Programmer
Nov 21, 2006
1
BE
Hi,

I've stumbled upon the following when importing a text file with floating points generated by a java application. The following one gives an invalid floating point operation when loading into a TFloatField

531.1861582473471

while the others don't give an exception:

529.9518191598611
534.4721380018583

Further testing showed that the fraction part .1861582 is still okay, but .18615824 isn't

now, I could solve this exception, by using Set8087CW to mask the exceptions while loading the file.

However I'm wondering why this exception is triggered in the first place. Is the fraction for that specific floating point invalid for Delphi and not for Java?

What is the issue behind this?

Thanks in advance!

 
Or my guess would be that the representation doesn't exactly fit the field that TFloatField is masking. As my documentation says, this is a field with 15 significant digits. If my count is correct, all your numbers have 16 significant digits, which would no doubt cause the problem. Perhaps this is related to some in-system text to float conversion routine, especially to try and make sure there is no data loss for truncation as it goes into the database.

Perhaps the reason that you're not seeing a consistent problem would be how the number is represented, that somehow it is able to store some numbers accurately and not others, for the field size. This is not unlike a similar problem with storing 5 digit numbers in a signed word. You can store +20000, but +70000 won't work.

If I remember floating-point types right, this sounds like TFloatField is a IEEE single type that is redefined via type clause. If you need 16 digits precision, you might try to see what you can do to use IEEE double types.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top