prestodb / presto

The official home of the Presto distributed SQL query engine for big data
http://prestodb.io
Apache License 2.0
15.87k stars 5.32k forks source link

How to format float in hexadecimal? #18389

Open 372046933 opened 1 year ago

372046933 commented 1 year ago

I want to cast float number to hexadecimal representation in string. Googled the docs but found no solution. Is it supported in Presto?

>>> (-0.1).hex()
'-0x1.999999999999ap-4'
>>> 3.14159.hex()
'0x1.921f9f01b866ep+1'
javrod87 commented 1 year ago

This is supported in Trino.

trino> select format('%a', -0.1e0);
         _col0
-----------------------
 -0x1.999999999999ap-4
(1 row)

trino> select format('%a', 3.14159e0);
        _col0
---------------------
 0x1.921f9f01b866ep1
(1 row)
372046933 commented 8 months ago

how to convert from '0x1.921f9f01b866ep1' to 3.14159e0?