Skip to content

Add functionality to detect big integers - #2139

Merged
lemire merged 1 commit into
simdjson:masterfrom
saleyn:big-integer
Feb 26, 2024
Merged

lemire merged 1 commit into
simdjson:masterfrom
saleyn:big-integer

Conversation

@saleyn

@saleyn saleyn commented Feb 24, 2024 •

Copy link
Copy Markdown
Contributor

This extention adds the ability to identify big integers in JSON input. A big integer is a number not fitting in the 64-bit space.

Typical use case:

  switch (element.type()) {
    case ondemand::json_type::number: {
      auto res = element.get_number();
      if (!res) {
        if (res == BIGINT_ERROR) {
          auto str = val.json_raw_token();
          // str contains the big number string, do something with it...
          ...
        }
        return res;
      }
      number num;
      res.get(num);
      // process num int64/uint64/double value
      break;
    ...
  }

@lemire

lemire commented Feb 25, 2024

Copy link
Copy Markdown
Member

I will review, soon.

@saleyn

saleyn commented Feb 26, 2024

Copy link
Copy Markdown
Contributor Author

One issue is that when a big integer is a root number, the current simdjson implementation creates a copy of a buffer, and therefore could truncate the value of a big integer. It is an unlikely event, but nevertheless, maybe it's possible to get rid of buffer copying for numbers?

@lemire

lemire commented Feb 26, 2024

Copy link
Copy Markdown
Member

it's possible to get rid of buffer copying for numbers?

Pull requests are invited.

@lemire

lemire commented Feb 26, 2024

Copy link
Copy Markdown
Member

This looks quite good to me. Let me run a few additional checks.

@lemire

lemire commented Feb 26, 2024

Copy link
Copy Markdown
Member

Ok. This is solid. Merging. I will do some extra work after merging (additional tests and docs).

@lemire
lemire merged commit 7832588 into simdjson:master Feb 26, 2024
@lemire lemire mentioned this pull request Feb 26, 2024
@lemire

lemire commented Feb 26, 2024

Copy link
Copy Markdown
Member

@saleyn

therefore could truncate the value of a big integer.

This is a real issue but I will check in a workaround before releasing this.

@saleyn

saleyn commented Mar 11, 2024

Copy link
Copy Markdown
Contributor Author

therefore could truncate the value of a big integer.

This is a real issue but I will check in a workaround before releasing this.

@lemire, are you planning to include this workaround in the next release?

@lemire

lemire commented Mar 11, 2024

Copy link
Copy Markdown
Member

@saleyn The workaround has been included. There should not be problem currently. If you think that there is a bug, consider raising it as a new issue.

@SCcagg5

SCcagg5 commented Jul 18, 2025

Copy link
Copy Markdown

Hi, reopenning it Currently still having the issue in python https://pypi.org/project/pysimdjson/

simdjson.Parser().parse(json.dumps({"q": 111111111111111111111111})))
  File "simdjson/csimdjson.pyx", line 465, in csimdjson.Parser.parse
RuntimeError: BIGINT_ERROR: Big integer value that cannot be represented using 64 bits

Not sure if this should be fixed using 7.0.2

@lemire

lemire commented Jul 18, 2025

Copy link
Copy Markdown
Member

@SCcagg5 I think you are reporting the issue in the wrong repo. The code that you are presenting looks like Python code.

@SCcagg5

SCcagg5 commented Jul 18, 2025

Copy link
Copy Markdown

@lemire That's the repo pinned on the package page sry

@lemire

lemire commented Jul 18, 2025

Copy link
Copy Markdown
Member

@SCcagg5 I think you are using @TkTech's excellent wrapper at https://github.com/TkTech/pysimdjson

In simdjson per se (which is a C++ library), we reject 111111111111111111111111 as this cannot be represented as a standard type in C or C++.

E.g., compilers would issue the following error:

integer literal is too large to be represented in any integer type

It is possible, in simdjson, to provide your own way to handle such large numbers, but given that there is no standard way to represent a number like 111111111111111111111111, we leave it up to the user of the library.

If you need to start big integers, the standard approach is to embed them into a string.

If you just mean the floating-point value, then it is typically gets serialized as 1.1111111111111111e+23.

I refer you to the JSON specification (https://www.rfc-editor.org/rfc/rfc8259) which discusses JSON portability.

@lemire

lemire commented Jul 18, 2025

Copy link
Copy Markdown
Member

This issue here is resolved. Any discussion regarding pysimdjson should be taken to https://github.com/TkTech/pysimdjson

@simdjson simdjson locked as resolved and limited conversation to collaborators Jul 18, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants