+ 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
Saurabh Tiwari - avatar
12 Réponses
+ 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
Dennis - avatar
+ 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
Saurabh Tiwari - avatar
+ 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
Dread
Dread - avatar
+ 3
Dennis can you explain how to do that. Thnx😊
24th Jan 2019, 2:19 PM
Saurabh Tiwari
Saurabh Tiwari - avatar
+ 2
How big does the number have to be?
23rd Jan 2019, 7:30 PM
Dread
Dread - avatar
+ 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
Dennis - avatar
+ 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
Dennis - avatar
+ 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
Sahil Bhakat - avatar
+ 1
Default 10^200
23rd Jan 2019, 7:33 PM
Saurabh Tiwari
Saurabh Tiwari - avatar
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
Sahil Bhakat - avatar
0
Do you have to use it in a comparison statement or something? ?
23rd Jan 2019, 7:37 PM
Sahil Bhakat
Sahil Bhakat - avatar
0
Dennis but it is not supported in SL's compiler
24th Jan 2019, 6:28 AM
Saurabh Tiwari
Saurabh Tiwari - avatar