Making your own suffix number like 1.2f and 8589934592L but for larger number than long long

Hello everyone!

My wish is to pass larger number than long long (64bit) to function.
For passing long long we have to but L to the end of the number but
the question is that can i create my own custom tag or sign to handle
even bigger number?

example:
1
2
3
4
5
6
7
8
9
10
11
// long long
void longlongfunc( long long in );
// my own invention
void myintfunc( myint in );

int main() {

longlongfunc(8589934592L);
myintfunc(1099511627776M);
return 0
}


Edit:

I found out that what i wanted is suffix number and i found out that
the max value of it can be long long or unsigned long long.

Is there any trick or something that i could pass a number like this:
1099511627776 for example.

Thanks!
Last edited on
You could create your own user-defined literals ...

http://en.cppreference.com/w/cpp/language/user_literal

... but you still need a type that can handle large numbers like that. Create your own class that uses multiple integer values internally, or use a library like GMP or Boost.Multiprecision.

https://gmplib.org/
http://www.boost.org/doc/libs/1_57_0/libs/multiprecision/doc/html/index.html
Sounds like you need to use a bigint class.
as i understood correctly that there is just no way to do this:
 
myintfunc(1099511627776M);


Because the largest thing that can be is long long as there were told.
I can create class that hold 128 or more bit value easily but using this = operator
to set is not the option then?
The only way would be
= "1099511627776"
Am i right or is there another way?
You've been asked to hold a number larger than the supported built in type. But a user defined type can be used that implements a larger value.
You can do myintfunc(1099511627776_M); (note the underscore, user-defined literals must use it). And yes, your operator""_M will have to return some custom type (or at least a boost multiprecision type) (Edit: if that number were actually too big for 64 bit, thank you Peter87!)
Last edited on
You realize 1099511627776 is small enough to be stored in a 64 bit variable?
@Peter87 you're right but this is just an example number.
If you feel better then the new number can be 4294967296*4294967296*256 :)

Topic archived. No new replies allowed.