Hi All

Hi All,

I am doing some precision maths and have a Delphi (v Tokyo 10.1) extended data type i.e. 18 significant figures, up to 17 decimal places, and want to save such values to a Firebird 2.1 database so it is retrieved exactly the same as it is saved.

It should be pretty simple to save some float values to a Firebird database, right? But I’m not having much luck. I can only seem to get 6 significant places to save to the database. Bigger numbers than that then Firebird throws and error.

Questions:

1. What field definition in Firebird is used to represent a floating point with suitable precision and decimal places for a Delphi extended (18 sig places) data type? Numeric[18,17], Decimal[18,17] data types (which are apparently equivalent in Firebird > v 2.0), or something else? Apparently Firebird internally stores the float value as an integer, but multiplies the float value by a scaling factor to move the decimal point all the way to the right side. The float range is set by the the limit of the 64 bit integer.

2. I am compiling a 32 bit application on a 64 bit Windows computer. I have read that Windows 64 bit processors treat 64 bit floating points like they were double (15 sig places) not extended (18 sig places). Does this mean I can only achieve double data type precision even with an extended Delphi data type in my 32 bit app on a 64 bit machine, and need to reduce the numbers to double precision 15 sig places?

3. For a Firebird Insert statement, what text formatting of the value as text within the SQL statement is needed to successfully save such floating point numbers, and what float value range is possible? Despite Googling, and checking the Firebirdsql user groups, I can’t find SQL examples.

4. In Delphi, which format function to use to get such a suitable text rendition of the extended number? There are many. E.g. FloatToStr, FloatToStrF, FormatFloat, FloatToText, FloatToTextFmt, Value.toString.

Any ideas? Any help much appreciated.

Cheers,

Martin
PS will also post to the Firebird community too

Comments

  1. Good advice Asbjorn. I have set up double precision fields in Firebird. But the odd thing is that retrieved values from the DB have a maximum of only six decimal places to the right of the decimal point even if they have up to 14 sig places in total for large numbers. The values sent to Firebird have more decimal places than that. Values are being rounded to six. With sigmoid nodes values are less than 1 so I need the greater decimal precision. Anyway Ill try to figure it out. Firebird internally saves floats as an integer value and a scaling factor. This limit on integer range i think is the problem.

    ReplyDelete
  2. Never used Firebird, but it does seem to support double floats natively: firebirdsql.org - Floating-Point Data Types

    Have you tried that?

    ReplyDelete
  3. Yes the retrieved value is way different to the value sent to Fitebird with Firebird Float datatypes. Pragmatically I might save the extended value as an immutable text string. Problem solved.

    ReplyDelete

Post a Comment