0

Not Yet Answered # Large data type in c++

Is there a data type that can allow a user to input a 25 digit number... because the largest data type for numbers that i know is long long int and uintmax_t which can only store 18 numbers (i'm not sure about this)... because my problem should allow a user to input 25 numbers... If a larger data type is impossible, is there another way??? (I'm a beginner to c++ and i'm really sorry if this question sounds stupid) :)

Banfa 597 mike_2000_17 2,669 rubberman 1,109 David W 119 Hey, so I wanna ask how I need to create a method who will remove word if in that word is 2 same chars. Example: "Potato" in this word there is a 2 "o" chars so this word will need to be removed. "Forum" in this word there is no ...

0

0

A 64bit integer is the largest native type currently in C++. However you are not the first person to have this problem and the way round it is to use a big integer classes. Classes of this nature can normally hold any number of digits which they do by using a vector of smaller integers to hold the values.

If you want you could try writing one yourself, it is a quite interesting exercise but if you just want to get on with the coding then try looking at Boost or googling "C++ BigInt"

1

Using a BigInt library is one solution.

Also, what are those digits?

If this is just a very big number, then you might just use a floating-point type instead (`float`

or `double`

) which don't really have an upper-limit (well, they do, but it's like 1e308), and instead, have a limited-precision (about 18 significant digits).

If the digits are actually something like a serial number, social security number, bank account number or anything like that, then you most likely don't need to be doing any math operations on those numbers (e.g., you can't add two social security numbers!). So, in this case, you don't really need to store the number as an actual number (integer), but instead, you could just store it as a string (text), or some other ad hoc representation (like 5 integers, one for each chunk of 5 digits). That's what you normally do for long numbers that are not mathematical in nature. This is because the BigInt classes are usually overkill for this situation because of all the math operations they bring into the picture (that you won't use).

0

There are a number of unlimited precision math tools. The most used one is probably boost. Here is a wikipedia article about arbitray precision math tools: http://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic

0

If you would like some ideas about coding / using big Integers, this link may give you a start ...

Also, you may like to know that Python comes with big integers ... (and big decimal precision also) ... so you may like to consider doing your program in Python?

*Edited 2 Years Ago by David W*: fixed typo

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

Hello All ...

Iam Getting An Error With try to excecute the stored procedure .

I have Have Sql database , the stored procedure like so :

```
USE [MPRS]
GO
/****** Object: StoredProcedure [dbo].[Search_Licenses_By_Number] Script Date: 26-Nov-16 8:06:52 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE ...
```

I don’t want at this stage work on a big separate project as I've already got plenty ...