+ 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.

23rd Jan 2019, 6:57 PM
Saurabh Tiwari
+ 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.
24th Jan 2019, 2:42 PM
Dennis
+ 4
Default Sahil Bhakat thanks guys but i have to use modulo (%) operator and double doesnt allow it
23rd Jan 2019, 7:28 PM
Saurabh Tiwari
+ 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).
23rd Jan 2019, 7:17 PM
+ 3
Dennis can you explain how to do that. Thnxđ
24th Jan 2019, 2:19 PM
Saurabh Tiwari
+ 2
How big does the number have to be?
23rd Jan 2019, 7:30 PM
+ 2
Here is a big integer library: https://mattmccutchen.net/bigint/ It's pretty old though, but still good.
23rd Jan 2019, 8:30 PM
Dennis
+ 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.
24th Jan 2019, 9:07 AM
Dennis
+ 1
Yeah Default is right you can use long double it has a range from -1.7Ă10^(4932) upto 1.7Ă10^(4932).
23rd Jan 2019, 7:22 PM
Sahil Bhakat
+ 1
Default 10^200
23rd Jan 2019, 7:33 PM
Saurabh Tiwari
0
Or you you have to put variable somewhere where double will give give you a error
23rd Jan 2019, 7:32 PM
Sahil Bhakat
0
Do you have to use it in a comparison statement or something? ?
23rd Jan 2019, 7:37 PM
Sahil Bhakat
0
Dennis but it is not supported in SL's compiler
24th Jan 2019, 6:28 AM
Saurabh Tiwari