KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums kdb+ C++ convert large decimal to KDB

  • C++ convert large decimal to KDB

    Posted by ekallivrousis on October 4, 2021 at 12:00 am
    I need help to find out if there is compatible function in c++ class used to connect to db that would convert the large(24) decimal place to datatype compatible to kdb
    ekallivrousis replied 9 months ago 4 Members · 6 Replies
  • 6 Replies
  • davidcrossey

    Member
    October 5, 2021 at 12:00 am

    Hi @ekallivrousis,

    You could use the Double / Float type as per the C API Reference

    Thanks for posting your query on the forums!

    Kind regards,

    David

  • Laura

    Administrator
    October 5, 2021 at 12:00 am

    Hi David,
    To elaborate on @ekallivrousis comment, we are trying to use 128-bit floating point data type (instead of 64-bit(8 byte double) ) to support 24 decimal places instead of 16 decimals supported by double. Currently, as per C API Reference KDB+ supports 4byte(float) and 8byte(double).  Is there were way to store 128-bit floating point values ?

  • rocuinneagain

    Member
    October 5, 2021 at 12:00 am

    You can see an example of mapping a decimal to either a list of bytes or scaling to a double in this interface.

  • ekallivrousis

    Member
    October 21, 2021 at 12:00 am

    Hey rocuinneagain,

    Correct me if im wrong but this is to do math in C correct? I want to do math operations in the KDB database. The c program will be just putting the data into DB

  • rocuinneagain

    Member
    October 26, 2021 at 12:00 am

    These are examples of using the C interface to extend the Kdb+ database.

     

    Documentation is here:

    https://code.kx.com/q/interfaces/using-c-functions/

    It shows an example of writing a new ‘add’ function in C:

    #include"k.h" 
    #ifdef __cplusplus extern "C"{ #endif K add(K x,K y) { if(x->t!=-KJ||y->t!=-KJ) 
         return krr("type"); 
         return kj(x->j+y->j); } 
    #ifdef __cplusplus } #endif

    Then this can be used from inside a Kdb+ process:

    q)add:(`add 2:(`add;2)) 
    q)add[3;4] 
    7

    This is a possible method to add math functions for 128-bit floating point numbers inside Kdb+.

  • ekallivrousis

    Member
    November 2, 2021 at 12:00 am

    Thank you for the above this is a big step in right direction for us.

    if we store large decimal will precision be lost when storing in kdb and querying to display on ui via java

     

     

Log in to reply.