Skip to content

Big integers should be returned as string (~JSON_BIGINT_AS_STRING) #9

Closed

Description

@JanTvrdik

I think that it is better to return large integers as string instead of casting them to float.

What do you think? Any tips, how to efficiently decide whether string contains integer larger than MAX_INT?

Activity

  1. Majkl578 commented on Apr 9, 2014

    @Majkl578

    Any tips, how to efficiently decide whether string contains integer larger than MAX_INT?

    Some cute regexp?

  2. JanTvrdik commented on Apr 9, 2014

    @JanTvrdik
    ContributorAuthor

    This is what I have now – JanTvrdik@c302826

  3. JanTvrdik commented on Apr 9, 2014

    @JanTvrdik
    ContributorAuthor

    What to do with numbers such as 0x123456789123456781345678913? I would prefer to return them as decimal string however I'm not aware of any efficient solution to perform the conversion.

  4. milo commented on Apr 9, 2014

    @milo
    Member

    What about E_USER_WARNING on big number? To force user enclose it in quotes as a string. JSON has the JSON_BIGINT_AS_STRING only for interoperability between 32-bit and 64-bit systems.

  5. milo commented on Apr 9, 2014

    @milo
    Member

    What to do with numbers such as 0x123456789123456781345678913? I would prefer to return them as decimal string however I'm not aware of any efficient solution to perform the conversion.

    The only sane way I know in PHP is the GMP extension.

  6. Majkl578 commented on Apr 9, 2014

    @Majkl578

    What about E_USER_WARNING on big number? To force user enclose it in quotes as a string.

    Please, don't. JSON NEON is not something you always manually construct in the application, it's rather given from elsewhere, really not something you control directly (thus should not trigger an error).

  7. JanTvrdik commented on Apr 9, 2014

    @JanTvrdik
    ContributorAuthor

    Please, don't. JSON is not something you manually construct

    1. We're talking about NEON here 2) JSON RFC allows a JSON parser to restrict the range of numbers it can handle

    But still agreed, warning is the solution I would like to avoid.

  8. mishak87 commented on Apr 10, 2014

    @mishak87

    There is no sane way how to handle big numbers or have you forgotten about very large decimals?

    It should be string representation of given number or native PHP representation if possible. This is the simple solution

    We can add custom number parser into mix as a fallback or parameter with default set to sane parser. Quite easy, hard problem of what to do with numbers will be solved by user.

    In my magic ball I see this heading to custom number parser with default implementation that handles numbers of all colours and sizes.

  9. added a commit that references this issue on Jun 18, 2024
    0321dc3
  10. added 2 commits that reference this issue on Jun 26, 2024
    b95f3ca
    b2b28ae
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions