Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does libjson support 64 bit int types?

Tags:

c++

json

libjson

I am trying to push a 64 bit integer data to a JSONNode using json.push_back call

    uint64_t myHigh = 0x10;          
    uint64_t myLow = 0x12;
    uint64_t myFinal = 0;


    myFinal = (myHigh << 32) | myLow ;

    std::cout << "val = 0x" << std::hex << myFinal << "\n";-----(1)
    JSONNode jvData;

    jvData.push_back(JSONNode("value",myFinal));
    std::cout<<jvData.write();--------------------------(2)

The cout (1) gives a value 0xa0000000c The cout (2) shows a value 12.

I expect the cout (2) value to be 42949672972 but doesnt seem to work as expected

Does Json support 64 bit int??

like image 782
payyans4u Avatar asked Aug 31 '25 17:08

payyans4u


1 Answers

64 bits integers cannot be represented in JSON since JavaScript internally codes values as 64 bits floating point values (http://ecma262-5.com/ELS5_HTML.htm#Section_8.5).

Thus, you are limited to 53 bits of precision (2^53).

If you want to exchange 64 bits integers, you may use strings or split the 64 integer in two 32 bits integers and then recombine them (What is the accepted way to send 64-bit values over JSON?).

like image 53
Matthieu Rouget Avatar answered Sep 02 '25 06:09

Matthieu Rouget