offbrand
A collection of generic, reference counted datastructures in C for C
|
obint Method Implementation More...
Functions | |
obint * | obint_new (int64_t num) |
Creates a new obint with the given integer. More... | |
int64_t | obint_value (const obint *a) |
Returns the value stored in obint as an integer. More... | |
obint * | obint_from_string (const obstring *numstr) |
Creates a new obint with value indicated by given string. More... | |
obstring * | obint_to_string (const obint *a) |
Creates an instance of obstring containing a string representation of the value of an obint. More... | |
obint * | obint_copy (const obint *a) |
Creates an instance of obint with the same value as the argument obint. More... | |
uint8_t | obint_is_zero (const obint *a) |
Checks if an instance of obint is zero and returns the boolean truth value. More... | |
uint8_t | obint_is_negative (const obint *a) |
Checks if an instance of obint is negative and returns the boolean truth value. More... | |
obint * | obint_add (const obint *a, const obint *b) |
Creates a new obint containing the sum of two obint values. More... | |
obint * | obint_add_primitive (const obint *a, int64_t b) |
Creates a new obint containing the sum of an obint and a machine integer. More... | |
obint * | obint_subtract (const obint *a, const obint *b) |
Creates a new obint containing the difference of two obint values. More... | |
obint * | obint_subtract_primitive (const obint *a, int64_t b) |
Creates a new obint containing the difference of an obint and a machine integer. More... | |
obint * | obint_multiply (const obint *a, const obint *b) |
Creates a new obint containing the product of two obint values. More... | |
obint * | obint_multiply_primitive (const obint *a, int64_t b) |
Creates a new obint containing the product of an obint and a machine integer. More... | |
obint * | obint_divide (const obint *a, const obint *b) |
Creates a new obint containing the quotient resule of integer division between two obint values,. More... | |
obint * | obint_divide_primitive (const obint *a, int64_t b) |
Creates a new obint containing the quotient of an obint and a machine integer. More... | |
obint * | obint_mod (const obint *a, const obint *b) |
Creates a new obint containing the remainder of integer division between two obint values,. More... | |
obint * | obint_mod_primitive (const obint *a, int64_t b) |
Creates a new obint containing the remainder of integer division of an obint and a machine integer. More... | |
obint * | obint_create_default (uint64_t num_digits) |
Default constructor for obint. More... | |
ob_hash_t | obint_hash (const obj *to_hash) |
Hash function for obint. More... | |
int8_t | obint_compare (const obj *a, const obj *b) |
Compares two instances of obint. More... | |
int8_t | obint_compare_magnitudes (const obint *a, const obint *b) |
Compares magnitudes of two instances of obint. More... | |
void | obint_display (const obj *to_print) |
Descriptor for an instance of obint, prints relevant information about the class to stderr. More... | |
void | obint_destroy (obj *to_dealloc) |
Destructor for obint. More... | |
obint * | obint_add_unsigned (const obint *a, const obint *b) |
Creates a new integer as a result of addition between two obints with sign value ignored. More... | |
obint * | obint_subtract_unsigned (const obint *a, const obint *b) |
Creates a new integer as a result of subtraction between two obints with sign ignored. More... | |
obint * | obint_multiply_unsigned (const obint *a, const obint *b) |
Creates a new integer as a result of multiplication between two obints with sign ignored. More... | |
obint * | obint_reduce (const obint *a, const obint *b, const obint *approx, uint8_t quotient) |
Creates a new integer as a result of divison or modulus between two obints with sign ignored. More... | |
uint64_t | obint_most_sig (const obint *a) |
Returns the index where the most significant non-zero digit occurs, or zero if there are no non-zero digits. More... | |
void | obint_split (const obint *a, uint64_t i, obint **b1, obint **b0) |
Splits the obint into two obint instances at given index. More... | |
void | obint_shift (obint *a, uint64_t m) |
Shifts the obint the given number of digits to the left, in place, essentially unsigned multiplication by 10^m. More... | |
int64_t | obint_magnitude (const obint *a) |
Returns the unsigned value of the obint. More... | |
void | obint_set_max_digits (uint8_t digits) |
Sets the number of digits operated on in a primitive from 1 to 17. More... | |
Variables | |
uint8_t | int64_max_digits = 17 |
obint Method Implementation
Creates a new obint containing the sum of two obint values.
a | A non-NULL pointer to type obint |
b | A non-NULL pointer to type obint |
Creates a new obint containing the sum of an obint and a machine integer.
a | A non-NULL pointer to type obint |
b | A signed 64 bit machine integer |
Creates a new integer as a result of addition between two obints with sign value ignored.
a | A non-NULL pointer to type obint |
b | A non-NULL pointer to type obint |
Compares two instances of obint.
a | A non-NULL obj pointer to type obint |
b | A non-NULL obj pointer to type obint |
OB_LESS_THAN | obj a is less than b |
OB_GREATER_THAN | obj a is greater than b |
OB_EQUAL_TO | obj a is equal to b |
Compares magnitudes of two instances of obint.
a | A non-NULL pointer to type obint |
b | A non-NULL pointer to type obint |
OB_LESS_THAN | Magnitude of a a is less than b |
OB_GREATER_THAN | Magnitude of a is greater than to b |
OB_EQUAL_TO | Magnitude of a is equal to b |
Creates an instance of obint with the same value as the argument obint.
a | A non-NULL pointer to type obint |
obint* obint_create_default | ( | uint64_t | num_digits) |
Default constructor for obint.
num_digits | Approximate number of digits required to store the entire, always overestimate to ensure enough space is reserved |
void obint_destroy | ( | obj * | to_dealloc) |
Destructor for obint.
to_dealloc | An obj pointer to an instance of obint with reference count of 0 |
void obint_display | ( | const obj * | to_print) |
Descriptor for an instance of obint, prints relevant information about the class to stderr.
to_print | A non-NULL obj pointer to an instance of type obint |
Creates a new obint containing the quotient resule of integer division between two obint values,.
a | A non-NULL pointer to type obint |
b | A non-NULL pointer to type obint |
Creates a new obint containing the quotient of an obint and a machine integer.
a | A non-NULL pointer to type obint |
b | A signed 64 bit machine integer |
Creates a new obint with value indicated by given string.
numstr | A non-NULL pointer to an obstring instance containing only digit characters and possibly one '-' character at the beginning of the string to indicate a negative value |
Hash function for obint.
to_hash | An obj pointer to an instance of obint |
uint8_t obint_is_negative | ( | const obint * | a) |
Checks if an instance of obint is negative and returns the boolean truth value.
a | A non-NULL pointer to type obint |
0 | The argument is positive |
non-zero | The argument is negative |
uint8_t obint_is_zero | ( | const obint * | a) |
Checks if an instance of obint is zero and returns the boolean truth value.
a | A non-NULL pointer to type obint |
0 | The argument is non-zero |
non-zero | The argument is zero |
int64_t obint_magnitude | ( | const obint * | a) |
Returns the unsigned value of the obint.
a | A non-NULL pointer to type obint |
Creates a new obint containing the remainder of integer division between two obint values,.
a | A non-NULL pointer to type obint |
b | A non-NULL pointer to type obint |
Creates a new obint containing the remainder of integer division of an obint and a machine integer.
a | A non-NULL pointer to type obint |
b | A signed 64 bit machine integer |
uint64_t obint_most_sig | ( | const obint * | a) |
Returns the index where the most significant non-zero digit occurs, or zero if there are no non-zero digits.
a | A non-NULL pointer to type obint |
Creates a new obint containing the product of two obint values.
a | A non-NULL pointer to type obint |
b | A non-NULL pointer to type obint |
Creates a new obint containing the product of an obint and a machine integer.
a | A non-NULL pointer to type obint |
b | A signed 64 bit machine integer |
Creates a new integer as a result of multiplication between two obints with sign ignored.
a | A non-NULL pointer to type obint |
b | A non-NULL pointer to type obint |
Multiplication performed using the Karatsuba multiplcation algorithm
obint* obint_new | ( | int64_t | num) |
Creates a new obint with the given integer.
num | Integer value for new obint |
Creates a new integer as a result of divison or modulus between two obints with sign ignored.
a | A non-NULL pointer to type obint |
b | A non-NULL pointer to type obint |
approx | A non-NULL pointer to type obint used to accumulate a quotient value |
quotient | A boolean value, 0 indicates that a remainder should be returned, non-zero indicates a quotient should be returned |
void obint_set_max_digits | ( | uint8_t | digits) |
Sets the number of digits operated on in a primitive from 1 to 17.
digits | An integer between 2 and 17 inclusive |
void obint_shift | ( | obint * | a, |
uint64_t | m | ||
) |
Shifts the obint the given number of digits to the left, in place, essentially unsigned multiplication by 10^m.
int
a | A non-NULL pointer to type obint |
m | Number of digits to shift |
Splits the obint into two obint instances at given index.
a | A non-NULL pointer to type obint to be split |
i | The integer index where the split occurs, where a-digits[i] is placed in the most significant section of the split |
b1 | A reference to a pointer to type obint, used to return the most significant section of the obint being split |
b0 | A reference to a pointer to type obint, used to return the least significant section of the obint being split |
If index i extends beyond the bounds of a then b1 is set to point to a 0 obint and b2 is set to point to a copy of a. a is treated as unsigned for this operation
Creates a new obint containing the difference of two obint values.
a | A non-NULL pointer to type obint |
b | A non-NULL pointer to type obint |
Creates a new obint containing the difference of an obint and a machine integer.
a | A non-NULL pointer to type obint |
b | A signed 64 bit machine integer |
Creates a new integer as a result of subtraction between two obints with sign ignored.
a | A non-NULL pointer to type obint, larger or equal to b |
b | A non-NULL pointer to type obint, smaller or equal to a |
Creates an instance of obstring containing a string representation of the value of an obint.
a | A non-NULL pointer to type obint |
int64_t obint_value | ( | const obint * | a) |
Returns the value stored in obint as an integer.
a | A non-NULL pointer to type obint |
uint8_t int64_max_digits = 17 |
maximum number of decimal digits to operate on as one int64_t