1

I know that The maximum value for a variable of type unsigned long long in C++ is:

18,446,744,073,709,551,615

but I don't know that how can I set value of a variable to an amount that is more than 18,446,744,073,709,551,615?

Nathan Pierson
  • 5,461
  • 1
  • 12
  • 30
  • 3
    Use a large integer library if you need exact precision, or a floating point type if you can deal with not being able to represent values exactly. – Nathan Pierson Aug 06 '22 at 14:38
  • 2
    Use a big-number / arbitrary-precision library. – Richard Critten Aug 06 '22 at 14:38
  • 2
    There is no maximum value for `unsigned long long` in the C++ standard. There is a minimum range that it must support, and implementations are free to provide a larger size. That "maximum" value depends on the compiler that you're using. You're right that it's typically the largest value supported. – Pete Becker Aug 06 '22 at 15:26

2 Answers2

1

In vanilla C++ you can't, however, you can use Boost's multi-precision library.

1

maybe you can use __int128,the only problem is that you can't use cin,cout or printf but you can write a function like that:

//output
inline void write(__int128 x)
{
     if(x<0) putchar('-'),x=-x;
     if(x>9) write(x/10);
     putchar(x%10+'0');
}
//input
inline __int128 read()
{
    __int128 X=0,w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=x*10+(ch-'0'),ch=getchar();
    return w?-X:X;
}
Rickyxrc
  • 86
  • 4
  • Your compiler might already optimize `x * 10 to x * 8 + x * 2`. Unless you have a performance problem, better to stay with more readable code. – Phil1970 Aug 06 '22 at 15:46