StrToFloat and who is wrong: Delphi or ASE / SQL Server

I recently found a strange thing: the result

var
  d: double;
begin
  d := StrToFloat('-1.79E308');

does not match string value '-1.79E308' converted to field type ASE float and SQL Server via

INSERT INTO my_table (my_float_field) VALUES (-1.79E308)

For a Delphi memory dump 9A BB AD 58 F1 DC EF FF
For the ASE / SQL Server value in the package when selected 99 BB AD 58 F1 DC EF FF.

Who is wrong, both servers or Delphi?

+4
source share
1 answer

The premise that we are working on is that it StrToFloatgives the closest representable binary floating-point value to a decimal value.

, , . , 1 . Python, :

>>> import struct
>>> struct.unpack('!d', 'ffefdcf158adbb9a'.decode('hex'))[0]
-1.7900000000000002e+308
>>> struct.unpack('!d', 'ffefdcf158adbb99'.decode('hex'))[0]
-1.79e+308

, Python , , . , ffefdcf158adbb99 , -1.79e+308 Python, , ffefdcf158adbb99 . , Delphi .

, , :

>>> hex(struct.unpack('<Q', struct.pack('<d', float('-1.79e308')))[0])
'0xffefdcf158adbb99L'

, 32- Delphi- ffefdcf158adbb99, 64- Delphi- ffefdcf158adbb9a. .

+1

Source: https://habr.com/ru/post/1618727/


All Articles