-2

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)?

robinCTS
  • 5,746
  • 14
  • 30
  • 37
Arya Sudan
  • 1
  • 1
  • 2
  • Sure, just define a class, like `class ReallybigInt{ ...};`, you just need to define how it is supposed to work in the class. – Aganju Nov 12 '17 at 05:10
  • 1
    [Google search.](https://www.google.com/search?source=hp&ei=CtgHWuXPHtO2jwPA1onIDQ&q=bigint+c%2B%2B&oq=BigInt+C%2B%2B&gs_l=psy-ab.1.0.0l5j0i22i30k1l5.1633.8522.0.15772.11.10.0.0.0.0.99.591.10.10.0....0...1.1.64.psy-ab..1.10.588.0..0i131k1j0i10k1.0.sFD451JBL0U) – jwdonahue Nov 12 '17 at 05:13
  • Do you really need 12-bytes? Or do you just want integers with more than 10-digits? – Buddy Nov 12 '17 at 05:32
  • more than 10 digits anyhow – Arya Sudan Nov 12 '17 at 10:06
  • whenever I input a number having more than 10 digits (store in long long) .... it stores a garbage value but works fine for 10 digits and lower – Arya Sudan Nov 12 '17 at 10:16
  • Add the code for your non-working program. – Buddy Nov 12 '17 at 22:17
  • turbo c is a 16 bit compiler so a 32 bit int is the biggest ( http://www.cs.technion.ac.il/~nikol/material/types_sizes.pdf and http://www.itlnet.net/programming/program/Reference/tc/ng71ec0.html and http://ltcpp.blogspot.co.nz/2012/07/c-data-types-variables-constants.html). If you need bigger you can use a arbitrary precision number library like GNU GMP ( https://gmplib.org/ ) or you get a 32bit or 64bit compiler. Have a look at https://stackoverflow.com/questions/45085435/how-to-use-long-long-keyword-in-turbo-c-3-2-compiler and https://stackoverflow.com/questions/2486893/long-integer-problem – Jerry Jeremiah Nov 14 '17 at 00:51
  • If you want to use turbo c then you will need an arbitrary precision library. There is a list here: https://en.wikipedia.org/wiki/List_of_arbitrary-precision_arithmetic_software – Jerry Jeremiah Nov 14 '17 at 00:56

3 Answers3

1

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

Buddy
  • 10,874
  • 5
  • 41
  • 58
0

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.

iBug
  • 35,554
  • 7
  • 89
  • 134
0

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

user2033775
  • 153
  • 9