Recent

Author Topic: New float fields contain 6E-154  (Read 9863 times)

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
New float fields contain 6E-154
« on: October 20, 2021, 02:49:18 pm »
Or, 6.01347001699907E-154 to be exact. This is with a FoxPro database, accessed with TDbf. If I append a new record in an existing database, this is the default value for float fields. What could this be? A wrong TableLevel or Version? I set those to 25 and 7.0 respectively, but I'm not sure what they should be.


Thaddy

  • Hero Member
  • *****
  • Posts: 14159
  • Probably until I exterminate Putin.
Re: New float fields contain 6E-154
« Reply #1 on: October 20, 2021, 03:13:15 pm »
Exact?
Specialize a type, not a var.

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: New float fields contain 6E-154
« Reply #2 on: October 20, 2021, 03:38:41 pm »
Well, no, probably not :) It's probably the smallest possible number.

0.0000000000000000 with 16 decimals, but not exactly 0.
« Last Edit: October 20, 2021, 03:44:31 pm by SymbolicFrank »

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: New float fields contain 6E-154
« Reply #3 on: October 21, 2021, 04:40:37 am »
No, not the smallest. This number is $2020202020..... in hex I believe. More like spaces maybe?

Try it here, check "Raw hexadecimal"
https://www.exploringbinary.com/floating-point-converter/
« Last Edit: October 21, 2021, 04:43:16 am by engkin »

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: New float fields contain 6E-154
« Reply #4 on: October 21, 2021, 10:08:56 am »
I was wondering if this should be the value used for a NULL. Well, everything seems to work and with correct formatting it looks fine (the TDBGrid defaults to scientific notation), but it's annoying.

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: New float fields contain 6E-154
« Reply #5 on: October 21, 2021, 10:38:31 am »
I was wondering if this should be the value used for a NULL.
No, NULL is not stored as an encoded data value but in a special location in the dataset data buffer outside the data value bytes.

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: New float fields contain 6E-154
« Reply #6 on: October 21, 2021, 01:57:03 pm »
I'll dig into it tomorrow. Perhaps it's a textfield at some point.

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: New float fields contain 6E-154
« Reply #7 on: October 22, 2021, 11:58:18 am »
Yup, it's a string of spaces:

Code: Pascal  [Select][+][-]
  1. procedure TDbfFile.InitDefaultBuffer;
  2. ..
  3.     // binary (non-text) field? (foxpro memo fields are binary, but dbase not)
  4.     if (TempFieldDef.NativeFieldType in ['I', 'O', '@', '+', '0', 'W', 'Y'])
  5.         or ((TempFieldDef.NativeFieldType = 'M') and (TempFieldDef.Size = 4) {Visual FoxPro?}) then
  6.       FillChar(PChar(FDefaultBuffer+TempFieldDef.Offset)^, TempFieldDef.Size, 0);
  7.  

Which is defined as:

Code: Pascal  [Select][+][-]
  1. procedure TDbfFieldDef.VCLToNative;
  2. begin
  3.   FNativeFieldType := #0;
  4.   // to do: look into ftBytes support; e.g. Visual FoxPro varbytes?
  5.   case FFieldType of
  6. ..
  7.     ftFloat, ftSmallInt, ftWord
  8. {$ifdef SUPPORT_INT64}
  9.       , ftLargeInt
  10. {$endif}
  11. {$ifdef SUPPORT_LONGWORD}
  12.       , ftLongWord, ftShortInt, ftByte
  13. {$endif}
  14.                :
  15.       FNativeFieldType := 'N'; //numerical
  16. ..
  17.     ftBlob     :
  18.       case DBFVersion of
  19.         xFoxPro:
  20.           FNativeFieldType := 'P'; //picture; best we can do
  21.         xVisualFoxPro:
  22.           FNativeFieldType := 'W'; //blob
  23.         xBaseIII,xBaseIV:
  24.           FNativeFieldType := 'M'; //memo; best we can do
  25.         xBaseV,xBaseVII:
  26.           FNativeFieldType := 'B'; //binary
  27.  

It thinks it is a 'B' field, while it should be an 'F' (Float) field, "new" to FoxPro...

Is there a better DataSet component / library for manipulating FoxPro databases?

korba812

  • Sr. Member
  • ****
  • Posts: 390
Re: New float fields contain 6E-154
« Reply #8 on: October 22, 2021, 12:40:15 pm »
Could you please attach a sample dbf file?

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: New float fields contain 6E-154
« Reply #9 on: October 22, 2021, 12:49:17 pm »
It's the default TDbf component, it should be part of any Lazarus install. The files are in: fpcsrc\packages\fcl-db\src\dbase .

korba812

  • Sr. Member
  • ****
  • Posts: 390
Re: New float fields contain 6E-154
« Reply #10 on: October 22, 2021, 12:53:04 pm »
I was referring to dbf file produced by FoxPro that you are trying to open with TDbf in Lazarus.

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: New float fields contain 6E-154
« Reply #11 on: October 22, 2021, 03:01:48 pm »
Is there a better DataSet component / library for manipulating FoxPro databases?
I don't know. But during my work at MyDbfStudio I learned that the fpc version of TDbf is a fork of https://sourceforge.net/p/tdbf/code/HEAD/tree/. Both versions have diverged to some degree, and both do get some changes occasionally. So, there is some chance that the sourceforce TDbf can handle FoxPro files better - just a wild guess... I would recommend that you test this version of the component. But be aware that keeping two equally named packages within an installation calls for trouble; therefore, I would not install the source forge version, but - against all rules - add the path the its sources to the search path of your project. Create the TDbf component at runtime and remove the TDbf package from your program requirements. Then you can test the sourceforge version of TDbf. Of course these are very massive changes to your project, and it is absolutely necessary that you conserve the previous state in a backup.

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: New float fields contain 6E-154
« Reply #12 on: October 22, 2021, 03:47:16 pm »
Test .DBF. The last field is a float.

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: New float fields contain 6E-154
« Reply #13 on: October 22, 2021, 04:29:49 pm »
I don't know. But during my work at MyDbfStudio I learned that the fpc version of TDbf is a fork of https://sourceforge.net/p/tdbf/code/HEAD/tree/

I just checked, but the FPC/Laz version supports more field types and is more complete.

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: New float fields contain 6E-154
« Reply #14 on: October 22, 2021, 05:04:51 pm »
I confirm the issue with this file. The file provided seems to be TableLevel 30 (Visual FoxPro). When I create such a dbf file with an ftFloat field myself, the ftFloat field behaves as expected. What's wrong here?

 

TinyPortal © 2005-2018