offbrand
A collection of generic, reference counted datastructures in C for C
|
obint Private Interface More...
#include "../obint.h"
Go to the source code of this file.
Classes | |
struct | obint_struct |
obint internal structure, encapsulating all data needed for an instance of obint More... | |
Functions | |
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... | |
obint Private Interface
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 |
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 |
Hash function for obint.
to_hash | An obj pointer to an instance of obint |
int64_t obint_magnitude | ( | const obint * | a) |
Returns the unsigned value of the obint.
a | A non-NULL pointer to type obint |
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 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
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 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 |