+ 3
using big integer values in cpp
how can we use big integer values in cpp? is there any library ? i have already tried long long unsigned int and the requirement of my program is even more than this.
12 odpowiedzi
+ 2
Saurabh Tiwari The easy way would be to use a string and simply apply addition and subtraction like you learned in school.
You know add 2 digits and keep track of any carries.
The more efficient, longer and less trivial solution would be to an array and store each number in base 2^64-1.
I recommend that you download the library and read through its source code and learn from it, which does exactly that.
+ 4
Default
Sahil Bhakat
thanks guys
but i have to use modulo (%) operator and double doesnt allow it
+ 3
I know it isn't an integer, but... how about long double?
This is 128-bits (2^128 MAX), opposed to unsigned long long int's (2^64 MAX).
+ 3
Dennis can you explain how to do that.
Thnx😊
+ 2
How big does the number have to be?
+ 2
Here is a big integer library: https://mattmccutchen.net/bigint/
It's pretty old though, but still good.
+ 2
Saurabh Tiwari No it's not, you could implement a simple big int class yourself though. :)
Sadly using long double isn't accurate anymore after 2^64-1.
+ 1
Yeah Default is right you can use long double it has a range from -1.7×10^(4932) upto 1.7×10^(4932).
+ 1
Default 10^200
0
Or you you have to put variable somewhere where double will give give you a error
0
Do you have to use it in a comparison statement or something? ?
0
Dennis but it is not supported in SL's compiler