paul_bignumbers.h
IntroductionArbitrary precision arithmetic library for C/C++. DiscussionImplementation is included when PAUL_BIGNUMBERS_IMPLEMENTATION or PAUL_IMPLEMENTATION is defined.
Functions
_bigfloat_to_bigintInternal function to convert big float to big integer. bignum_err_t _bigfloat_to_bigint( const REAL *bigfloat, INT *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionTruncates a big float to a big integer. _bigint_to_bigfloatInternal function to convert big integer to big float. bignum_err_t _bigint_to_bigfloat( const INT *bigint, REAL *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionConverts a big integer to a big float representation. bigcomplex_absoluteComputes the absolute value (magnitude) of a big complex number. bignum_err_t bigcomplex_absolute( const COMPLEX *a, REAL *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionCalculates |a| and stores the result as a big float. bigcomplex_addAdds two big complex numbers. bignum_err_t bigcomplex_add( const COMPLEX *a, const COMPLEX *b, COMPLEX *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionComputes a + b and stores the result in the provided buffer. bigcomplex_conjugateComputes the conjugate of a big complex number. bignum_err_t bigcomplex_conjugate( const COMPLEX *a, COMPLEX *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionFlips the sign of the imaginary part. bigcomplex_divideDivides two big complex numbers. bignum_err_t bigcomplex_divide( const COMPLEX *a, const COMPLEX *b, COMPLEX *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionComputes a / b and stores the result in the provided buffer. bigcomplex_equalsChecks if two big complex numbers are equal. bool bigcomplex_equals( const COMPLEX *a, const COMPLEX *b); ParametersReturn ValueTrue if equal, false otherwise. DiscussionReturns true if a == b, false otherwise. bigcomplex_freeFrees the memory associated with a big complex. void bigcomplex_free( COMPLEX *complex); ParametersDiscussionReleases all resources allocated for the big complex. The pointer becomes invalid after this call. bigcomplex_is_zeroChecks if a big complex number is zero. bool bigcomplex_is_zero( const COMPLEX *a); ParametersReturn ValueTrue if zero, false otherwise. DiscussionReturns true if both real and imaginary parts are zero. bigcomplex_multiplyMultiplies two big complex numbers. bignum_err_t bigcomplex_multiply( const COMPLEX *a, const COMPLEX *b, COMPLEX *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionComputes a * b and stores the result in the provided buffer. bigcomplex_newCreates a new big complex number initialized to zero. COMPLEX *bigcomplex_new( size_t precision); ParametersReturn ValueA pointer to the new big complex, or NULL on failure. DiscussionAllocates memory for a new COMPLEX structure and initializes it to 0+0i. bigcomplex_new_copyCreates a copy of an existing big complex. COMPLEX *bigcomplex_new_copy( const COMPLEX *src); ParametersReturn ValueA pointer to the new copy, or NULL on failure. DiscussionAllocates a new COMPLEX and copies all data from the source. bigcomplex_new_from_doublesCreates a new big complex from double values. COMPLEX *bigcomplex_new_from_doubles( double real, double imag, size_t precision); ParametersReturn ValueA pointer to the new big complex, or NULL on failure. DiscussionAllocates a new COMPLEX with real and imaginary parts from doubles. bigcomplex_new_from_floatsCreates a new big complex from real and imaginary big floats. COMPLEX *bigcomplex_new_from_floats( const REAL *real, const REAL *imag, size_t precision); ParametersReturn ValueA pointer to the new big complex, or NULL on failure. DiscussionAllocates a new COMPLEX with the given real and imaginary parts. bigcomplex_new_from_stringCreates a new big complex from a string representation. COMPLEX *bigcomplex_new_from_string( const char *str, size_t precision); ParametersReturn ValueA pointer to the new big complex, or NULL on failure. DiscussionParses the input string and creates a big complex. bigcomplex_subtractSubtracts two big complex numbers. bignum_err_t bigcomplex_subtract( const COMPLEX *a, const COMPLEX *b, COMPLEX *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionComputes a - b and stores the result in the provided buffer. bigcomplex_to_stringConverts a big complex number to a string representation. char *bigcomplex_to_string( const COMPLEX *complex); ParametersReturn ValueA pointer to the string, or NULL on failure. The caller must free the string. DiscussionReturns a dynamically allocated string representing the complex number. bigfloat_absoluteComputes the absolute value of a big float. bignum_err_t bigfloat_absolute( const REAL *a, REAL *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionTakes the absolute value of the input big float and stores it in the result buffer. bigfloat_acosComputes the arccosine of a big float. bignum_err_t bigfloat_acos( const REAL *a, REAL *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionCalculates acos(a) and stores the result. bigfloat_add(const REAL *, const REAL *, REAL *)Adds two big floats. bignum_err_t bigfloat_add( const REAL *a, const REAL *b, REAL *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionComputes a + b and stores the result in the provided result buffer. bigfloat_add(const REAL *, const REAL *, REAL *)Adds two big floats. bignum_err_t bigfloat_add( const REAL *a, const REAL *b, REAL *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionComputes a + b and stores the result in the provided result buffer. bigfloat_asinComputes the arcsine of a big float. bignum_err_t bigfloat_asin( const REAL *a, REAL *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionCalculates asin(a) and stores the result. bigfloat_atanComputes the arctangent of a big float. bignum_err_t bigfloat_atan( const REAL *a, REAL *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionCalculates atan(a) and stores the result. bigfloat_atan2Computes the arctangent of y/x. bignum_err_t bigfloat_atan2( const REAL *y, const REAL *x, REAL *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionCalculates atan2(y, x) and stores the result. bigfloat_ceilComputes the ceiling of a big float. bignum_err_t bigfloat_ceil( const REAL *a, REAL *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionRounds up to the nearest integer and stores the result. bigfloat_compareCompares two big floats. int bigfloat_compare( const REAL *a, const REAL *b); ParametersReturn ValueThe comparison result. DiscussionReturns -1 if a < b, 0 if a == b, 1 if a > b. bigfloat_copyCopies one big float to another. bignum_err_t bigfloat_copy( const REAL *src, REAL *dest); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionCopies all data from the source big float to the destination. bigfloat_cosComputes the cosine of a big float. bignum_err_t bigfloat_cos( const REAL *a, REAL *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionCalculates cos(a) and stores the result. bigfloat_coshComputes the hyperbolic cosine of a big float. bignum_err_t bigfloat_cosh( const REAL *a, REAL *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionCalculates cosh(a) and stores the result. bigfloat_divideDivides two big floats. bignum_err_t bigfloat_divide( const REAL *a, const REAL *b, REAL *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionComputes a / b and stores the result in the provided result buffer. bigfloat_equalsChecks if two big floats are equal. bool bigfloat_equals( const REAL *a, const REAL *b); ParametersReturn ValueTrue if equal, false otherwise. DiscussionReturns true if a == b, false otherwise. bigfloat_expComputes the exponential function of a big float. bignum_err_t bigfloat_exp( const REAL *a, REAL *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionCalculates e^a and stores the result. bigfloat_floorComputes the floor of a big float. bignum_err_t bigfloat_floor( const REAL *a, REAL *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionRounds down to the nearest integer and stores the result. bigfloat_freeFrees the memory associated with a big float. void bigfloat_free( REAL *bigfloat); ParametersDiscussionReleases all resources allocated for the big float. The pointer becomes invalid after this call. bigfloat_greater_thanChecks if the first big float is greater than the second. bool bigfloat_greater_than( const REAL *a, const REAL *b); ParametersReturn ValueTrue if a > b, false otherwise. DiscussionReturns true if a > b, false otherwise. bigfloat_is_negativeChecks if a big float is negative. bool bigfloat_is_negative( const REAL *a); ParametersReturn ValueTrue if negative, false otherwise. DiscussionReturns true if the big float is negative, false otherwise. bigfloat_is_zeroChecks if a big float is zero. bool bigfloat_is_zero( const REAL *a); ParametersReturn ValueTrue if zero, false otherwise. DiscussionReturns true if the big float represents 0.0, false otherwise. bigfloat_less_thanChecks if the first big float is less than the second. bool bigfloat_less_than( const REAL *a, const REAL *b); ParametersReturn ValueTrue if a < b, false otherwise. DiscussionReturns true if a < b, false otherwise. bigfloat_logComputes the natural logarithm of a big float. bignum_err_t bigfloat_log( const REAL *a, REAL *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionCalculates ln(a) and stores the result. bigfloat_log10Computes the base-10 logarithm of a big float. bignum_err_t bigfloat_log10( const REAL *a, REAL *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionCalculates log10(a) and stores the result. bigfloat_log2Computes the base-2 logarithm of a big float. bignum_err_t bigfloat_log2( const REAL *a, REAL *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionCalculates log2(a) and stores the result. bigfloat_maxReturns the maximum of two big floats. bignum_err_t bigfloat_max( const REAL *a, const REAL *b, REAL *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionCompares a and b and stores the larger one in result. bigfloat_minReturns the minimum of two big floats. bignum_err_t bigfloat_min( const REAL *a, const REAL *b, REAL *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionCompares a and b and stores the smaller one in result. bigfloat_multiplyMultiplies two big floats. bignum_err_t bigfloat_multiply( const REAL *a, const REAL *b, REAL *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionComputes a * b and stores the result in the provided result buffer. bigfloat_negateNegates a big float. bignum_err_t bigfloat_negate( REAL *a); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionFlips the sign of the big float. Zero remains zero. bigfloat_new(size_t)Creates a new big float initialized to zero. REAL *bigfloat_new( size_t precision); ParametersReturn ValueA pointer to the new big float, or NULL on allocation failure. DiscussionAllocates memory for a new REAL structure and initializes it to represent 0.0 with the specified precision. bigfloat_new(size_t)Creates a new big float initialized to zero. REAL *bigfloat_new( size_t precision); ParametersReturn ValueA pointer to the new big float, or NULL on allocation failure. DiscussionAllocates memory for a new REAL structure and initializes it to represent 0.0 with the specified precision. bigfloat_new_copyCreates a copy of an existing big float. REAL *bigfloat_new_copy( const REAL *src); ParametersReturn ValueA pointer to the new copy, or NULL on failure. DiscussionAllocates a new big float and copies all data from the source. bigfloat_new_from_bigintCreates a new big float from a big integer. REAL *bigfloat_new_from_bigint( const INT *bigint, size_t precision); ParametersReturn ValueA pointer to the new big float, or NULL on failure. DiscussionConverts the big integer to a big float with the specified precision. bigfloat_new_from_doubleCreates a new big float from a double value. REAL *bigfloat_new_from_double( double value, size_t precision); ParametersReturn ValueA pointer to the new big float, or NULL on failure. DiscussionConverts the double to a big float with the specified precision. bigfloat_new_from_stringCreates a new big float from a string representation. REAL *bigfloat_new_from_string( const char *str, size_t precision); ParametersReturn ValueA pointer to the new big float, or NULL on failure. DiscussionParses the input string and creates a big float with the specified precision. bigfloat_powComputes the power of a big float raised to another. bignum_err_t bigfloat_pow( const REAL *base, const REAL *exp, REAL *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionCalculates base^exp and stores the result. bigfloat_powerRaises a big float to a power. bignum_err_t bigfloat_power( const REAL *base, const REAL *exponent, REAL *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionComputes base^exponent and stores the result in the provided result buffer. bigfloat_roundRounds a big float to the nearest integer. bignum_err_t bigfloat_round( const REAL *a, REAL *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionRounds to the nearest integer and stores the result. bigfloat_set_from_bigintSets a big float from a big integer. bignum_err_t bigfloat_set_from_bigint( REAL *bigfloat, const INT *bigint); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionConverts the big integer to a big float. bigfloat_set_from_doubleSets a big float from a double value. bignum_err_t bigfloat_set_from_double( REAL *bigfloat, double value); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionConverts the double to a big float representation. bigfloat_set_from_stringSets a big float from a string representation. bignum_err_t bigfloat_set_from_string( REAL *bigfloat, const char *str); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionParses the input string and sets the big float to the corresponding value. bigfloat_set_precisionSets the precision of a big float. bignum_err_t bigfloat_set_precision( REAL *bigfloat, size_t precision); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionUpdates the precision (number of significant decimal digits) for the big float. bigfloat_signReturns the sign of a big float. bignum_err_t bigfloat_sign( const REAL *a, REAL *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionReturns -1 for negative, 0 for zero, 1 for positive. bigfloat_sinComputes the sine of a big float. bignum_err_t bigfloat_sin( const REAL *a, REAL *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionCalculates sin(a) and stores the result. bigfloat_sinhComputes the hyperbolic sine of a big float. bignum_err_t bigfloat_sinh( const REAL *a, REAL *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionCalculates sinh(a) and stores the result. bigfloat_sqrtComputes the square root of a big float. bignum_err_t bigfloat_sqrt( const REAL *a, REAL *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionCalculates sqrt(a) and stores the result in the provided buffer. bigfloat_subtractSubtracts two big floats. bignum_err_t bigfloat_subtract( const REAL *a, const REAL *b, REAL *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionComputes a - b and stores the result in the provided result buffer. bigfloat_tanComputes the tangent of a big float. bignum_err_t bigfloat_tan( const REAL *a, REAL *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionCalculates tan(a) and stores the result. bigfloat_tanhComputes the hyperbolic tangent of a big float. bignum_err_t bigfloat_tanh( const REAL *a, REAL *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionCalculates tanh(a) and stores the result. bigfloat_to_bigintConverts a big float to a big integer. INT *bigfloat_to_bigint( const REAL *bigfloat); ParametersReturn ValueA pointer to the new big integer, or NULL on failure. DiscussionTruncates the big float to an integer value. bigfloat_to_doubleConverts a big float to a double. double bigfloat_to_double( const REAL *bigfloat); ParametersReturn ValueThe double value. DiscussionAttempts to convert the big float to a double value. bigfloat_to_stringConverts a big float to a string representation. char *bigfloat_to_string( const REAL *bigfloat); ParametersReturn ValueA pointer to the string, or NULL on failure. The caller must free the string. DiscussionReturns a dynamically allocated string representing the big float. bigfloat_truncTruncates a big float to an integer. bignum_err_t bigfloat_trunc( const REAL *a, REAL *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionRemoves the fractional part and stores the integer part. bigint_absoluteComputes the absolute value of a big integer. bignum_err_t bigint_absolute( const INT *a, INT *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionTakes the absolute value of the input big integer and stores it in the result buffer. bigint_addAdds two big integers. bignum_err_t bigint_add( const INT *a, const INT *b, INT *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionComputes a + b and stores the result in the provided result buffer. bigint_andPerforms bitwise AND on two big integers. bignum_err_t bigint_and( const INT *a, const INT *b, INT *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionComputes a & b and stores the result in the provided result buffer. Operands must be non-negative. bigint_compare(const INT *, const INT *)Compares two big integers. int bigint_compare( const INT *a, const INT *b); ParametersReturn ValueThe comparison result. DiscussionReturns -1 if a < b, 0 if a == b, 1 if a > b. bigint_compare(const INT *, const INT *)Compares two big integers. int bigint_compare( const INT *a, const INT *b); ParametersReturn ValueThe comparison result. DiscussionReturns -1 if a < b, 0 if a == b, 1 if a > b. bigint_create_powerCreates a big integer representing base raised to an exponent. INT *bigint_create_power( int64_t base, size_t exponent); ParametersReturn ValueA pointer to the new big integer, or NULL on failure. DiscussionComputes base^exponent and returns a new big integer with that value. bigint_divideDivides two big integers. bignum_err_t bigint_divide( const INT *a, const INT *b, INT *quotient, INT *remainder); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionComputes quotient and remainder of a / b. Stores quotient in quotient and remainder in remainder if provided. bigint_ensure_capacityEnsures a big integer has sufficient capacity. bignum_err_t bigint_ensure_capacity( INT *bigint, size_t required_capacity); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionResizes the digit array if necessary to accommodate at least the required number of digits. bigint_equalsChecks if two big integers are equal. bool bigint_equals( const INT *a, const INT *b); ParametersReturn ValueTrue if equal, false otherwise. DiscussionReturns true if a == b, false otherwise. bigint_factorialComputes the factorial of a big integer. bignum_err_t bigint_factorial( const INT *a, INT *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionCalculates a! for non-negative a. bigint_freeFrees the memory associated with a big integer. void bigint_free( INT *bigint); ParametersDiscussionReleases all resources allocated for the big integer. The pointer becomes invalid after this call. bigint_gcdComputes the greatest common divisor of two big integers. bignum_err_t bigint_gcd( const INT *a, const INT *b, INT *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionUses the Euclidean algorithm to find GCD(a, b). bigint_greater_thanChecks if the first big integer is greater than the second. bool bigint_greater_than( const INT *a, const INT *b); ParametersReturn ValueTrue if a > b, false otherwise. DiscussionReturns true if a > b, false otherwise. bigint_is_negativeChecks if a big integer is negative. bool bigint_is_negative( const INT *a); ParametersReturn ValueTrue if negative, false otherwise. DiscussionReturns true if the big integer is negative, false otherwise. bigint_is_zeroChecks if a big integer is zero. bool bigint_is_zero( const INT *a); ParametersReturn ValueTrue if zero, false otherwise. DiscussionReturns true if the big integer represents 0, false otherwise. bigint_isprimeChecks if a big integer is prime. bool bigint_isprime( const INT *a); ParametersReturn ValueTrue if prime, false otherwise. DiscussionReturns true if a is a prime number, false otherwise. bigint_lcmComputes the least common multiple of two big integers. bignum_err_t bigint_lcm( const INT *a, const INT *b, INT *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionCalculates LCM(a, b) = |a*b| / GCD(a, b). bigint_less_thanChecks if the first big integer is less than the second. bool bigint_less_than( const INT *a, const INT *b); ParametersReturn ValueTrue if a < b, false otherwise. DiscussionReturns true if a < b, false otherwise. bigint_moduloComputes the modulo of two big integers. bignum_err_t bigint_modulo( const INT *a, const INT *b, INT *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionComputes a % b and stores the result in the provided result buffer. bigint_multiplyMultiplies two big integers. bignum_err_t bigint_multiply( const INT *a, const INT *b, INT *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionComputes a * b and stores the result in the provided result buffer. bigint_negateNegates a big integer. bignum_err_t bigint_negate( INT *a); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionFlips the sign of the big integer. Zero remains zero. bigint_newCreates a new big integer initialized to zero. INT *bigint_new( void); Return ValueA pointer to the new big integer, or NULL on allocation failure. DiscussionAllocates memory for a new INT structure and initializes it to represent the value 0. bigint_new_copyCreates a copy of an existing big integer. INT *bigint_new_copy( const INT *src); ParametersReturn ValueA pointer to the new copy, or NULL on failure. DiscussionAllocates a new big integer and copies all data from the source. bigint_new_from_int64Creates a new big integer from a 64-bit integer value. INT *bigint_new_from_int64( int64_t value); ParametersReturn ValueA pointer to the new big integer, or NULL on failure. DiscussionAllocates and initializes a big integer with the given int64_t value. bigint_new_from_stringCreates a new big integer from a string representation. INT *bigint_new_from_string( const char *str); ParametersReturn ValueA pointer to the new big integer, or NULL on failure. DiscussionParses the input string to create a big integer. Supports decimal notation with optional leading sign. bigint_notPerforms bitwise NOT on a big integer. bignum_err_t bigint_not( const INT *a, INT *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionComputes ~a and stores the result in the provided result buffer. The operand must be non-negative. bigint_orPerforms bitwise OR on two big integers. bignum_err_t bigint_or( const INT *a, const INT *b, INT *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionComputes a | b and stores the result in the provided result buffer. Operands must be non-negative. bigint_powerRaises a big integer to a power. bignum_err_t bigint_power( const INT *base, const INT *exponent, INT *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionComputes base^exponent and stores the result in the provided result buffer. Only non-negative exponents are supported. bigint_set_from_int64Sets a big integer from a 64-bit integer. bignum_err_t bigint_set_from_int64( INT *bigint, int64_t value); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionConverts the int64_t value to a big integer representation. bigint_set_from_stringSets a big integer from a string representation. bignum_err_t bigint_set_from_string( INT *bigint, const char *str); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionParses the input string and sets the big integer to the corresponding value. bigint_shift_leftShifts a big integer left by a specified number of bits. bignum_err_t bigint_shift_left( const INT *a, size_t bits, INT *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionComputes a << bits and stores the result in the provided result buffer. bigint_shift_rightShifts a big integer right by a specified number of bits. bignum_err_t bigint_shift_right( const INT *a, size_t bits, INT *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionComputes a >> bits and stores the result in the provided result buffer. bigint_subtractSubtracts two big integers. bignum_err_t bigint_subtract( const INT *a, const INT *b, INT *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionComputes a - b and stores the result in the provided result buffer. bigint_to_bigfloatConverts a big integer to a big float. REAL *bigint_to_bigfloat( const INT *bigint); ParametersReturn ValueA pointer to the new big float, or NULL on failure. DiscussionCreates a big float from a big integer value. bigint_to_int64Converts a big integer to a 64-bit integer. int64_t bigint_to_int64( const INT *bigint); ParametersReturn ValueThe int64_t value, or INT64_MIN/INT64_MAX on overflow. DiscussionAttempts to convert the big integer to int64_t, may overflow. bigint_to_stringConverts a big integer to a string representation. char *bigint_to_string( const INT *bigint); ParametersReturn ValueA pointer to the string, or NULL on failure. The caller must free the string. DiscussionReturns a dynamically allocated string representing the big integer in decimal. bigint_to_string_baseConverts a big integer to a string in a specified base. char *bigint_to_string_base( const INT *bigint, int base); ParametersReturn ValueA pointer to the string, or NULL on failure. The caller must free the string. DiscussionReturns a string representation of the big integer in the given base (2-36). bigint_xorPerforms bitwise XOR on two big integers. bignum_err_t bigint_xor( const INT *a, const INT *b, INT *result); ParametersReturn ValueBIGNUM_OK on success, or an error code. DiscussionComputes a ^ b and stores the result in the provided result buffer. Operands must be non-negative. bignum_error_stringReturns a string description of a bignum error code. const char *bignum_error_string( bignum_err_t error); ParametersReturn ValueA string describing the error. DiscussionProvides a human-readable string for the given error code. Typedefs
bignum_err_tEnumeration of error codes for bignum operations. typedef enum bignum_err { BIGNUM_OK = 0, BIGNUM_ERROR_MEMORY, BIGNUM_ERROR_DIVIDE_BY_ZERO, BIGNUM_ERROR_INVALID_ARGS, BIGNUM_ERROR_OVERFLOW, BIGNUM_ERROR_UNDERFLOW } bignum_err_t; Fields
DiscussionDefines the possible error conditions that can occur during arbitrary precision arithmetic operations. COMPLEXRepresents an arbitrary precision complex number. FieldsDiscussionConsists of real and imaginary parts, each stored as a REAL. INTRepresents an arbitrary precision integer. typedef struct INT { uint32_t *digits; // Array of base-10^9 digits (least significant first) size_t length; // Number of used digits size_t capacity; // Allocated capacity bool negative; // Sign flag } INT; FieldsDiscussionUses a base-10^9 representation for efficient operations. The digits array stores the number in little-endian order (least significant digit first). REALRepresents an arbitrary precision floating-point number. typedef struct REAL { INT mantissa; // The significand as a big integer int32_t exponent; // Power of 10 exponent size_t precision; // Number of significant decimal digits bool negative; // Sign flag } REAL; FieldsDiscussionUses a significand (mantissa) and exponent representation. The mantissa is stored as a big integer, and the exponent is a power of 10. Macro Definitions
BIGNUM_BASEThe base used for big integer digit representation. #ifndef BIGNUM_BASE #define BIGNUM_BASE 1000000000UL // 10^9, fits in uint32_t #endif DiscussionDefines the base (10^9) for storing big integer digits, which fits in a uint32_t. BIGNUM_DEFAULT_EPSILONThe default epsilon for float comparisons. #ifndef BIGNUM_DEFAULT_EPSILON #define BIGNUM_DEFAULT_EPSILON 1e-30 // Default epsilon for float comparisons #endif DiscussionDefines the default epsilon value used for comparing big floats. BIGNUM_DEFAULT_PRECISIONThe default decimal precision for big floats. #ifndef BIGNUM_DEFAULT_PRECISION #define BIGNUM_DEFAULT_PRECISION 64 // Default decimal precision for big floats #endif DiscussionDefines the default number of significant decimal digits for big float operations. BIGNUM_DIGIT_BITSThe number of bits in each digit. #ifndef BIGNUM_DIGIT_BITS #define BIGNUM_DIGIT_BITS 30 // log2(BIGNUM_BASE), for efficient operations #endif DiscussionDefines the number of bits (log2(BIGNUM_BASE)) for efficient operations. |