`BigIntegers`

or `BigNum`

fit your needs.`BigIntehers`

can be integrated in your compiler libraries depending on how old it is.The GNU MP Bignum Library[^]

See more:

Hi everyone,

I am new to this site and to coding. Well, I am not completely new, as I have experimented with a bit of Excel VBA and HTML and CSS. I am just new to C++.

I am teaching myself how to code in C++ using*C++ Programming for the Absolute Beginner, 2nd Edition*.

Although I have done one of the Chapter 1 challenges, I notice that the program is imperfect.

**What I have tried:**

As a beginner who has just read the chapter on variables, I know that I used the short datatype, which can only store a limited amount of integers. Long datatype also can only store a limited amount of integers. Is there a possible datatype that can store an infinitely big number or just a very, very, very big number like 100,000,000,000,000,000,000,000,000,000 or 10^29 or one hundred octillion?

I am new to this site and to coding. Well, I am not completely new, as I have experimented with a bit of Excel VBA and HTML and CSS. I am just new to C++.

I am teaching myself how to code in C++ using

Although I have done one of the Chapter 1 challenges, I notice that the program is imperfect.

C++

Copy Code

/* Write a program that asks users for their names, that greets them, and that asks them for 2 numbers and then provides the sum. */ #include <iostream> #include <string> using namespace std; int main(void) { using std::cout; using std::cin; using std::string; string name = ""; short firstNumber, secondNumber, Sum; //ask for name cout << "What is your name?\n"; cin >> name; //greet user cout << "\nHello " << name.c_str() << "\n"; cout << "I am a smart computer. Give me 2 numbers, and I will add "; cout << "them together.\n"; //ask 2 numbers cout << "Input two numbers to add. \n"; cin >> firstNumber >> secondNumber; Sum = firstNumber + secondNumber; cout << "Your sum is: " << Sum << "\n"; return 0; }

As a beginner who has just read the chapter on variables, I know that I used the short datatype, which can only store a limited amount of integers. Long datatype also can only store a limited amount of integers. Is there a possible datatype that can store an infinitely big number or just a very, very, very big number like 100,000,000,000,000,000,000,000,000,000 or 10^29 or one hundred octillion?

Use Google and see if

The GNU MP Bignum Library[^]

`BigIntegers`

or `BigNum`

fit your needs.`BigIntehers`

can be integrated in your compiler libraries depending on how old it is.The GNU MP Bignum Library[^]

v2

Comments

5.

Thank you

5ed.

—SA

—SA

Thank you

I don't know what is "large variable", forget "infinitely large variable". Any computer is a finite-state machine. Does it tell you something? It computing, there is a concept of "infinity", but it's an abstraction, more exactly, a number of abstractions.

Also, the size of data is not the same as size of a variable.

Now, you should see the big difference between two related concepts. One thing is "very large number". Such numbers can be represented using*floating-point number*. First thing to understand is: representation of a really big number can carry pretty little amount of information. Isn't it a big number: 999^{999999}? :-) But it carries very modest amount of information. See also:

Floating point — Wikipedia, the free encyclopedia[^],

IEEE floating point — Wikipedia, the free encyclopedia[^].

Another thing is the number holding big volume of information, ideally, of the arbitrary size limited only by available computer memory. For simplicity, let's set aside such complicated thing as representation of arbitrary-size*real numbers*. Let's consider arbitrary integer number, represented precisely, without any approximation. Apparently, such numbers can be represented as a sequence of bits of arbitrary size, limited only by available memory. The usual name for such types is "big integer", or, for a type name,

The development of such classes is not even extremely difficult. Basically, you just mimic the operations learned in elementary schools arithmetic. Only I would not advice using strings to represent the sequence of 0..9 digits; such representation is utterly inefficient. It should be sequence of bits. You can do your search and find a number of available implementations (of different quality :-)).

—SA

Also, the size of data is not the same as size of a variable.

Now, you should see the big difference between two related concepts. One thing is "very large number". Such numbers can be represented using

Floating point — Wikipedia, the free encyclopedia[^],

IEEE floating point — Wikipedia, the free encyclopedia[^].

Another thing is the number holding big volume of information, ideally, of the arbitrary size limited only by available computer memory. For simplicity, let's set aside such complicated thing as representation of arbitrary-size

`BigInt`

, `BigInteger`

. Some of such types are really of unlimited size, but in C++ it's more usual to develop much weaker type where the maximum size is limited at the moment of object initialization.The development of such classes is not even extremely difficult. Basically, you just mimic the operations learned in elementary schools arithmetic. Only I would not advice using strings to represent the sequence of 0..9 digits; such representation is utterly inefficient. It should be sequence of bits. You can do your search and find a number of available implementations (of different quality :-)).

v2

Comments

No fair. Your username is pronounceable. Mine is just a set of numbers, as if the forum doesn't even bother giving me a natural-language name. :(

You can change your username quite easily.

5.

Thank you, Carlo.

—SA

—SA

a 5 for you too :-)

Thank you very much.

—SA

—SA

+5

Thank you, Matt.

—SA

—SA

Nice answer +5 :).

Thank you very much.

—SA

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject,
20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8
+1 (416) 849-8900