I am using the long
type for storing values but it doesn't store a number with more than 10 digits.
Is there any way to make a new integer type with extended memory size (e.g. 12 bytes or more)?
I am using the long
type for storing values but it doesn't store a number with more than 10 digits.
Is there any way to make a new integer type with extended memory size (e.g. 12 bytes or more)?
Use a long long
(or unsigned long long
), which is 64-bits and has a range of -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
http://en.cppreference.com/w/cpp/language/types#Range_of_values
You can write an implementation of arbitrary precision, which will allow you to store as many digits as you want, or use Python. You will have to implement basic arithmetics from scratch, but once you get its point, it won't be too hard.
The standard guarantees long long
to be at least 8 bytes long. If you want a 8-byte integer, try this:
#include <stdint.h>
int64_t a;
uint64_t b; // Unsigned 64-bit int
If your compiler complains that it doesn't know what int64_t
is, then there's no luck unless you implement an AP.
You can use enter https://github.com/cerevra/int/tree/master/v2
It`s a proposal to C++20, but it could be useful with modern c++14 compatible compilers too