Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to deal with very big numbers in Qt?
Forum Updated to NodeBB v4.3 + New Features

How to deal with very big numbers in Qt?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 4 Posters 1.6k Views 4 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    Infinity
    wrote on last edited by
    #1

    What is the best way to deal with very big numbers in Qt? I have numbers like this:

    123456789012345678901234
    

    I need to do basic math ( + - / *) with this numbers. Are there any libraries available which I could use for this?

    kshegunovK 1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #2

      I am not sure how to do this with just Qt. You could look at Boost Multiprecision. It handles various numbers of both integer and floating point and others.

      C++ is a perfectly valid school of magic.

      JKSHJ 1 Reply Last reply
      7
      • fcarneyF fcarney

        I am not sure how to do this with just Qt. You could look at Boost Multiprecision. It handles various numbers of both integer and floating point and others.

        JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by
        #3

        @fcarney said in How to deal with very big numbers in Qt?:

        I am not sure how to do this with just Qt. You could look at Boost Multiprecision. It handles various numbers of both integer and floating point and others.

        Another one is the GNU Multiple Precision library.

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        1 Reply Last reply
        6
        • I Infinity

          What is the best way to deal with very big numbers in Qt? I have numbers like this:

          123456789012345678901234
          

          I need to do basic math ( + - / *) with this numbers. Are there any libraries available which I could use for this?

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by kshegunov
          #4

          @Infinity said in How to deal with very big numbers in Qt?:

          What is the best way to deal with very big numbers in Qt?

          There's none. Qt doesn't deal in numbers itself.

          Are there any libraries available which I could use for this?

          Beside the mentioned obvious solutions, i.e. to pull a dependency in, your compiler may support an int128 type. For gcc that's __int128, which I think clang also supports. As far as I remember MSVC doesn't have it, though.
          boost's a fine option, I've worked with it and it's templated so everything is well optimized in-code. If you are very much against using it, you can use a tuple of standard 64bit ints and deal with the carry yourself. It's quite a lot of work to implement and test though, so I'd generally advise against it.

          Finally you can work with such numbers in floating point if the dynamic range is enough for your case. The advantage is the FPU is fast enough and you just cut off the irrelevant digits after you're done.
          Note: not with 24 decimal digits of required precision, though

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          5

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved