Unsolved How to deal with very big numbers in Qt?
-
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?
-
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.
-
@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.
-
@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 thinkclang
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