What is the best way to represent arbitrarily big numbers in c?

后端 未结 2 1659
北海茫月
北海茫月 2020-12-06 08:26

I\'m working on a project that requires me to work with numbers larger than the largest numerical datatype in c. I was thinking of using structs with bit fields to represent

相关标签:
2条回答
  • 2020-12-06 08:39

    I suggest to first check out the GNU MP Bignum library.

    If licensing is a problem you have to roll your own. My first choice for the data-type would be a simple array of unsigned chars along with some extra data to denote how large that array is.

    Something like this:

    typedef struct 
    {
      unsigned char * NumberData;
      size_t          AllocatedSize;
    } MyBigNum;
    

    Should be sufficient.

    0 讨论(0)
  • 2020-12-06 08:48

    The GNU MP Bignum Library would be my first choice.

    0 讨论(0)
提交回复
热议问题