waltermilner

Untitled

Apr 24th, 2018
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.19 KB | None | 0 0
  1. /****************************************************
  2.  
  3. A BigInt is held in a form of binary-coded decimal, in an array of
  4. unsigned long long elements
  5. ANSI requires an unsigned long long to be at least 18 X 10^18
  6. We hold 0 to 10^9-1 ( 9 decimal digits) in each element
  7. Then an intermediate product of the two = 10^18 will also fit into an unsigned long long
  8.  
  9. The sign is held in the 'sign' field as a char, + or -
  10.  
  11. The array is 1024 long, so we can handle up to 9216 decimal digits.
  12.  
  13. For bigger than this (!) the 'next' field points to another BigInt, as a linked list - so
  14. that there is no limit to the size of a number other than total memory.
  15.  
  16. This format is designed to be able to use processor instructions to do arithmetic in 10^9 size chunks.
  17.  
  18.  
  19. *****************************************************/
  20.  
  21. struct BIStruct
  22. {
  23. char sign;                          // + or -
  24. unsigned long long digits[1024];    // The digits, in 10^9 chunks
  25. int listCount;                      // 0,1,2.. through the linked list
  26. struct BIStruct * next;             // pointer to next block
  27. int elementCount;                   // array elements 0 to elementCount-1 are non-garbage
  28. };
  29.  
  30. typedef struct BIStruct BigInt;
Advertisement
Add Comment
Please, Sign In to add comment