Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /****************************************************
- A BigInt is held in a form of binary-coded decimal, in an array of
- unsigned long long elements
- ANSI requires an unsigned long long to be at least 18 X 10^18
- We hold 0 to 10^9-1 ( 9 decimal digits) in each element
- Then an intermediate product of the two = 10^18 will also fit into an unsigned long long
- The sign is held in the 'sign' field as a char, + or -
- The array is 1024 long, so we can handle up to 9216 decimal digits.
- For bigger than this (!) the 'next' field points to another BigInt, as a linked list - so
- that there is no limit to the size of a number other than total memory.
- This format is designed to be able to use processor instructions to do arithmetic in 10^9 size chunks.
- *****************************************************/
- struct BIStruct
- {
- char sign; // + or -
- unsigned long long digits[1024]; // The digits, in 10^9 chunks
- int listCount; // 0,1,2.. through the linked list
- struct BIStruct * next; // pointer to next block
- int elementCount; // array elements 0 to elementCount-1 are non-garbage
- };
- typedef struct BIStruct BigInt;
Advertisement
Add Comment
Please, Sign In to add comment