Big Integers (larger than long)

Anyone know how to handle numbers larger than long in kdb+?

I need to handle numbers with 20+ digits in kdb+. It seems there is no inbuilt data types for this, other than to store the number as a string or hex.

Does anyone know any KDB+ libraries to do hex math i.e. addition, multiplication on hex / binary numbers?

Alternatively, any C libraries to use?

Best,

Alexander

Hi Alexander,

I think __int128 is available in GCC as an extension. I would store those 16byte ints as guids on the kdb side and develop the necessary functions in C.
This is interesting, I might come back to you with some prototype code today/tomorrow.

Regards,

Andras

Thanks Andras,

I found a couple of C libraries that could be modified to integrate K structs:

https://github.com/SzigetiJ/biguint

https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&ved=2ahUKEwjwwrGww-7vAhUFi1wKHQaSD_AQFjANegQIFRAE&url=https%3A%2F%2Fwww3.cs.stonybrook.edu%2F~skiena%2F392%2Fprograms%2Fbignum.c&usg=AOvVaw3v2FJGLxIzrFT2uUzh5_C-

To anyone looking for Big Integer arithmetic in future, I made a C library to integrate into kdb at:

https://github.com/manifoldfinance/qBigInt

Another option, GCC’s __int128 extension as guid:
https://github.com/adotsch/c-extensions-to-q