My highschool (and a lot of others) offer c++ AP courses, where you take a test at the end of the year for $76 and can earn college credits.
Well part of the test is based on a class (a C++ class, not a school classroom) that you are suppose to learn during the year. This year the class is called BigInt, and can hold any size (non decimal) numbers (well, limited to how much memory you have available).
maybe do a search on BigInt and see what it turns up...
Help with HUGE numbers!?!
I took the AP exam last year. BigInt used a C++ class to store each digit in a string. Then worked on each term individually. (someone suggested this above). It isn''t exactly fast, but the method works. I personally disagree with the method it uses, it is slow and takes up way more memory than needed. Though, it is the easiest.
-Omalacon
-Omalacon
I give you an algorithm for division:
a/b
Stage 1:
Shift left b until the most significant 1 bit of b has the same position as the most significant 1 bit of a. Then x=2^(Number of bits shiftet).
Stage 2:
Then calculate a-x. With the amount of this difference you goto stage 1: /(a-x)//b. If a-x is positiv, you add /(a-x)//b to x, else you subtract it. You could implement this recursive and stop it if /(a-x)/
Visit our homepage: www.rarebyte.de.st
GA
a/b
Stage 1:
Shift left b until the most significant 1 bit of b has the same position as the most significant 1 bit of a. Then x=2^(Number of bits shiftet).
Stage 2:
Then calculate a-x. With the amount of this difference you goto stage 1: /(a-x)//b. If a-x is positiv, you add /(a-x)//b to x, else you subtract it. You could implement this recursive and stop it if /(a-x)/
Visit our homepage: www.rarebyte.de.st
GA
At work, our PC based applications do some talking to a Tandem computer. The biggest integer on the PC is 2^32 and the biggest integer on the is 2^64 (plus PC is intel format (byte reversed) and Tandem is correct format). We actually have some data that 2^32 would not handle so the Tandem uses their native format and we created longlong. This is a 2^64 integer in correct byte order (not intel format).
It should be very easy to extend to as many bytes as you like. For 2^1840 and no loss of precision you''ll need 230 bytes! We did functions for addition, subtraction, multiplication, divition, ascii to longlong,and longlong to ascii. Maybe kieren_j could compress your numbers for you with his Cold Fusion algorithm!
Since time for this bit of math magic is not a concern we just did it byte by byte, but I''m fairly certain the code can be optimized for a 32 byte word. Don''t know how fast or slow they are as is and thusly have no idea on what the effect of optimization should be, but it should speed them up. With your need for 230 bytes its not going to be super fast no matter what.
If you want like to have them e-mail me. I will have to clean them up a bit to remove some work related crap that you don''t need. As far as I know, all 6 functions are use in our code and have no problems, but there all no guarantees.
Michael L. Roberts
aka milo
mlbobs@telocity.com
It should be very easy to extend to as many bytes as you like. For 2^1840 and no loss of precision you''ll need 230 bytes! We did functions for addition, subtraction, multiplication, divition, ascii to longlong,and longlong to ascii. Maybe kieren_j could compress your numbers for you with his Cold Fusion algorithm!
Since time for this bit of math magic is not a concern we just did it byte by byte, but I''m fairly certain the code can be optimized for a 32 byte word. Don''t know how fast or slow they are as is and thusly have no idea on what the effect of optimization should be, but it should speed them up. With your need for 230 bytes its not going to be super fast no matter what.
If you want like to have them e-mail me. I will have to clean them up a bit to remove some work related crap that you don''t need. As far as I know, all 6 functions are use in our code and have no problems, but there all no guarantees.
Michael L. Roberts
aka milo
mlbobs@telocity.com
Michael (or milo2120),
Really?? Well, if you''ve got some time, could you e-mail it to sirius25@hotmail.com ?
Thanks alot!!!! =)
-Sage
Really?? Well, if you''ve got some time, could you e-mail it to sirius25@hotmail.com ?
Thanks alot!!!! =)
-Sage
quote:Original post by Sage
Hey!
I''m doing some math with pretty big #s (like 2^1840), but i can''t get it to work without an overflow, or using crappy float''s (and it''s important that i keep track of every digit)...
Could anybody help me with this, or refer me to a tutorial/website or something?
Thanks for your time!!
Hi,
I''m fairly new to programming, but, in such cases, you should probably get or design your own custom integer.
I had to do something like that last term, in my C++ class, and also the term before, in my C class.
For C++, you need a BigInt class, where you have]
class BigInt{
public:
//all the overloaded operators and get and set methods
private:
int array[1000]
// all the variables and flags required.
};
What you do is take string of up to 1000 characters, and, if the string is valid (no letters or non-numerals), convert each character into an int (with atoi()), then slot that int into the appropriate place in the array.
This assignment can actually be fun, if you do it right. But this is such an obvious problem that you could probably get a free bigint from one of the professional software houses.
Is this for school?
Stanley
Somewhat related to big numbers and datatypes
Most compilers have _int64 declarations
There''s also the
long long
Looking over the messages I see you are probably talking above that. But before developing a whole math system: Why the need for such big numbers?
ZoomBoy
A 2D RPG with skills, weapons, and adventure.
See my character editor, Tile editor and diary at
Check out my web-site
Most compilers have _int64 declarations
There''s also the
long long
Looking over the messages I see you are probably talking above that. But before developing a whole math system: Why the need for such big numbers?
ZoomBoy
A 2D RPG with skills, weapons, and adventure.
See my character editor, Tile editor and diary at
Check out my web-site
Like ZoomBoy, I''d also like to know why you need the big numbers.
Visit our homepage: www.rarebyte.de.st
GA
Visit our homepage: www.rarebyte.de.st
GA
Thanks for the responses, you guys are great!!!
No, i don't need this for school (unforunately my school only offers very, very basic programming courses in QBasic [on 386's])..
I. I do some pretty large numbered equations
II. For use with manipulating files as a whole number.
example: take a file, read it as bytes/bits, convert it into it's decimal representation.
foo.txt - 1010010101101010001010101111010100010101010
foo.txt - 35664623215984023540
(not a real base conversion here, typing in a hurry)
stuff like that....
-Sage
Edited by - Sage on 4/17/00 12:42:43 AM
No, i don't need this for school (unforunately my school only offers very, very basic programming courses in QBasic [on 386's])..
I. I do some pretty large numbered equations
II. For use with manipulating files as a whole number.
example: take a file, read it as bytes/bits, convert it into it's decimal representation.
foo.txt - 1010010101101010001010101111010100010101010
foo.txt - 35664623215984023540
(not a real base conversion here, typing in a hurry)
stuff like that....
-Sage
Edited by - Sage on 4/17/00 12:42:43 AM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement