int overflow question

P

Pat

Hi, I am developing a program to deal with very large integers. unsigned int
can not be used due to overflow.

Does there exist other integer type to store large integers? I want my
program can be used under Linux and Windows VC++ 6.0.

Thanks.

Pat
 
J

Jorge Rivera

Does there exist other integer type to store large integers? I want my
program can be used under Linux and Windows VC++ 6.0.

Not in standard C++. Largest you could get is long, but this is not
large enough for your needs.

You can google for such libraries, as there are abundant implementations.

Jorge L.
 
R

RM

I read it somewhere (can't remember the exact syntax) there you can specify
the int size. Basically, you can have say 64 bit int or even 128 bit int
but it has to be a power of two.
Note, I am not talking about creating Integer class, I am talking about
actually having user-specified int size.
 
K

Karthik

Pat said:
Hi, I am developing a program to deal with very large integers. unsigned int
can not be used due to overflow.

Does there exist other integer type to store large integers? I want my
program can be used under Linux and Windows VC++ 6.0.

Thanks.

Pat
You can think of a custom implementation of having a list of smaller
integers to represent a bigger one.
 
D

Denis Remezov

Pat said:
Hi, I am developing a program to deal with very large integers. unsigned int
can not be used due to overflow.

Does there exist other integer type to store large integers? I want my
program can be used under Linux and Windows VC++ 6.0.

Thanks.

Pat

As Jorge said, long and unsigned long are as large as it gets in the standard C++
as of yet.

[OT]
Large/big [arbitrary size] integer classes are great, but may happen to be much
more than you need. Assuming 64 bit is enough for you, here is a dirty quick fix:
Multiple compilers on multiple platforms support 64-bit integers as a primitive
type. Most commonly, "long long" is the one (with Microsoft it is "__int64").
It is non-standard, but I doubt you should have any problems if you are limited
to certain platforms. You could typedef your own type depending on the compiler
and use some form of compile-time asserts to make sure it has the minimum size
you need. Better yet, take a look at
http://www.boost.org/libs/integer/cstdint.htm
[/OT]

Denis
 
G

Gianni Mariani

Denis said:
Pat said:
Hi, I am developing a program to deal with very large integers. unsigned int
can not be used due to overflow.

Does there exist other integer type to store large integers? I want my
program can be used under Linux and Windows VC++ 6.0.

Thanks.

Pat


As Jorge said, long and unsigned long are as large as it gets in the standard C++
as of yet.

[OT]
Large/big [arbitrary size] integer classes are great, but may happen to be much
more than you need. Assuming 64 bit is enough for you, here is a dirty quick fix:
Multiple compilers on multiple platforms support 64-bit integers as a primitive
type. Most commonly, "long long" is the one (with Microsoft it is "__int64").

MSC++ 7.1 supports long long. (I know OP wants 6.0 support but it's just
one more reason to reconsider - 6.0 is a terrible C++ compiler.).
It is non-standard, but I doubt you should have any problems if you are limited
to certain platforms. You could typedef your own type depending on the compiler
and use some form of compile-time asserts to make sure it has the minimum size
you need. Better yet, take a look at
http://www.boost.org/libs/integer/cstdint.htm
[/OT]

When I looked at this a while back, I thought that GMP (
http://www.swox.com/gmp/ ) was the best alternative if speed was the
important factor. It has a C++ interface in the 4.0 version.
 
R

Richard Herring

RM <I_am_not_@_home.com> said:
I read it somewhere (can't remember the exact syntax) there you can specify
the int size. Basically, you can have say 64 bit int or even 128 bit int
but it has to be a power of two.
Note, I am not talking about creating Integer class, I am talking about
actually having user-specified int size.

I'm afraid you read wrong. The only built-in integer types the C++
standard gives you are (signed or unsigned) char, short, int, long.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,920
Members
47,464
Latest member
Bobbylenly

Latest Threads

Top