jtk icon indicating copy to clipboard operation
jtk copied to clipboard

Can some please implement the BigInteger data type?

Open itssamuelrowe opened this issue 5 years ago • 2 comments

BigInteger data type can be used for mathematical operations which involve very big integer calculations that are outside the limit of all available primitive data types in C.

For example factorial of 100 contains 158 digits. Obviously, it cannot be stored in any primitive data type available in C. However, with a BigInteger we can store large integer values as we want. The memory is allocated dynamically as required.

The structure of BigInteger can be something like this:

struct jtk_BigInteger_t {
   /* A sequence bytes that represent the integer value. */
    int32_t* m_values;
   /* The number of bytes occupied by this big integer. */
    int32_t m_capacity;
};

typedef struct jtk_BigInteger_t jtk_BigInteger_t;

Please try to implement the following operations:

  • addition
  • subtraction
  • division for quotient
  • multiplication
  • division for remainder
  • bitwise AND
  • bitwise OR
  • bitwise NOT

It would be great if you could add other operations, too.

itssamuelrowe avatar Oct 21 '19 05:10 itssamuelrowe

Hi,

I'm facing a little difficulty here.

  1. Can I use the source code of this: https://www.ibm.com/support/knowledgecenter/SSMQ79_9.5.1/com.ibm.egl.pg.doc/topics/pegl_core_c_bigint.html

  2. Can you please direct me on how I should modify the ESQL C BIGINT function for JTK or link a few learning resources?

  3. How do I check if it's working?

ghost avatar Oct 21 '19 14:10 ghost

I am not sure about it. I was not able to find its source code or license.

However, you can check out this repository. It is licensed under The Unlicence terms.

https://github.com/kokke/tiny-bignum-c

itssamuelrowe avatar Oct 21 '19 14:10 itssamuelrowe