Very large signed integer math question

This is a discussion on Very large signed integer math question within the C Programming forums, part of the General Programming Boards category; Here's a tough one...
How would one go about performing addition, subtraction, and multiplication on integers that are larger than ...

Very large signed integer math question

Here's a tough one...

How would one go about performing addition, subtraction, and multiplication on integers that are larger than the built in integer types for C? I've been thinking about this for a while, and cant seem to come up with a good answer.

> How would one go about performing addition, subtraction, and multiplication on integers that are larger than the built in integer types for C?
Search www.google.com for Arbitrary Precision Arithmetic, lots of good stuff.

one simple answer

you can store your data in floating points which provides even more data range , while this could be a temporary solution , you can create your own data structure that stores a very long integer by splitting it to 2-3 integers & you need to have your own arithmatic operator functions.

Prelude seems to be the most helpful with what you are asking. Using floats doesn't seem like it would be the best solution but if it is quick and accurate enough for you then go right ahead. There are a lot of ways of doing this. I think going for the library orbitz suggested is probably the simplest.

Re: one simple answer

Originally posted by krunal_dedhia you can store your data in floating points which provides even more data range

Actually, you will get more accuracy by just using a integer of the same size as the floating point value. Being able to represent a large integer isn't very helpful if you can't represent all of the other integers in between. It would only cause problems and innacurate calculations. A 4-byte integer would be better than a 4-byte floating point and an 8-byte integer would be better than an 8-byte floating point. Not only that, but if you used floating point values, your calculation would take longer and you wouldn't be able to directly use the mod operation.

If you're using msvc++ you can use

__int64

for a 64 bit integer which holds nearly 18 and a half quintillion different integers. That's

18,446,744,073,709,551,616

different values.

In most cases you won't have to go larger than that, but if you do, then ake your own datastructure to handle it.

VERY large ;)

well I'm definately going to have to use a data structure. I am looking to store and manipulate numbers on the order of 50+ digits. Here's what i was thinking...

make a struct to hold the data (myint), make a function that initializes a new "myint" and have other functions that do the addition, subtraction, and multiplication on the "myint" type.

Sounds easy enough, but I've been really busy lately so I havent had a chance to mess around with it. You guys think that sounds reasonable? I'll post some code if I get a chance to mess around with it.

If anyone would like to provide some more detailed suggestions please feel free to message me privately.