MPXL (Multiple Precision eXtended Library) - Big Integer Library for C
Introduction: A C library for arbitrary-precision integer arithmetic. Handles integers of any size limited only by available memory.
Uses:
- Mathematical computations
- Financial calculations
- Scientific computing
Features:
- Basic arithmetic operations (+, -, *, /, %)
- Bitwise operations
- Number theory functions
- Memory efficient
- Easy-to-use API
FUNCTIONS:
-
BigInt MAKE(char* a)
-> Creates a new BigInt from string -
BigInt createBigIntFromInt(long long value)
-> Creates BigInt from integer value -
BigInt copyBigInt(BigInt num)
-> Returns a copy of given BigInt -
void freeBigInt(BigInt num)
-> Frees memory allocated for BigInt -
BigInt addBigInt(BigInt a, BigInt b)
-> Returns a + b -
BigInt subtractBigInt(BigInt a, BigInt b)
-> Returns a - b -
BigInt multiplyBigInt(BigInt a, BigInt b)
-> Returns a * b -
BigInt divideBigInt(BigInt a, BigInt b)
-> Returns a / b -
BigInt modBigInt(BigInt a, BigInt b)
-> Returns a % b -
BigInt absBigInt(BigInt num)
-> Returns absolute value -
BigInt negateBigInt(BigInt num)
-> Returns negated value -
int compareBigInt(BigInt a, BigInt b)
-> Returns 1 if a>b, -1 if a<b, 0 if equal -
bool isPrime(BigInt num)
-> Checks if number is prime -
BigInt gcdBigInt(BigInt a, BigInt b)
-> Returns greatest common divisor -
BigInt lcmBigInt(BigInt a, BigInt b)
-> Returns least common multiple -
BigInt BigFactorial(BigInt num)
-> Returns factorial of num -
BigInt BigPower(BigInt base, BigInt exp)
-> Returns base^exp -
BigInt leftShiftBigInt(BigInt num, int shift)
-> Left shifts number by 'shift' bits -
BigInt rightShiftBigInt(BigInt num, int shift)
-> Right shifts number by 'shift' bits -
char* bigIntToString(BigInt num)
-> Converts BigInt to string -
void printBigInt(BigInt num)
-> Prints BigInt to stdout
MACROS:
-
ADD(a, b, ...)
-> Adds multiple BigInts (NULL terminated) -
SUB(a, b, ...)
-> Subtracts multiple BigInts -
MUL(a, b, ...)
-> Multiplies multiple BigInts -
DIVIDE(a, b)
-> Divides two BigInts -
MAX(a, b, ...)
-> Returns maximum of given BigInts -
MIN(a, b, ...)
-> Returns minimum of given BigInts
Example Usage:
#include "MPXL.h"
int main()
{
BigInt a = MAKE("123456789");
BigInt b = MAKE("6E700");
BigInt sum = ADD(&a, &b);
printBigInt(sum);
freeBigInt(a);
freeBigInt(b);
freeBigInt(sum);
}Notes:
- Always free BigInt objects after use
- NULL terminate variable argument lists
- Check for memory allocation errors
- Functions return new BigInt objects that must be freed