offbrand
A collection of generic, reference counted datastructures in C for C
 All Classes Files Functions Variables Typedefs Macros Groups
Classes | Functions
obint_private.h File Reference

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

obintobint_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...
 
obintobint_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...
 
obintobint_subtract_unsigned (const obint *a, const obint *b)
 Creates a new integer as a result of subtraction between two obints with sign ignored. More...
 
obintobint_multiply_unsigned (const obint *a, const obint *b)
 Creates a new integer as a result of multiplication between two obints with sign ignored. More...
 
obintobint_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...
 

Detailed Description

obint Private Interface

Author
theck

Function Documentation

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.

Parameters
aA non-NULL pointer to type obint
bA non-NULL pointer to type obint
Returns
An instance of obint, which may or may not have proper sign
int8_t obint_compare ( const obj a,
const obj b 
)

Compares two instances of obint.

Parameters
aA non-NULL obj pointer to type obint
bA non-NULL obj pointer to type obint
Return values
OB_LESS_THANobj a is less than b
OB_GREATER_THANobj a is greater than b
OB_EQUAL_TOobj a is equal to b
int8_t obint_compare_magnitudes ( const obint a,
const obint b 
)

Compares magnitudes of two instances of obint.

Parameters
aA non-NULL pointer to type obint
bA non-NULL pointer to type obint
Return values
OB_LESS_THANMagnitude of a a is less than b
OB_GREATER_THANMagnitude of a is greater than to b
OB_EQUAL_TOMagnitude of a is equal to b
obint* obint_create_default ( uint64_t  num_digits)

Default constructor for obint.

Parameters
num_digitsApproximate number of digits required to store the entire, always overestimate to ensure enough space is reserved
Returns
An instance of class obint
Warning
All public constructors should call this constructor and intialize individual members as needed, so that all base data is initialized properly.
void obint_destroy ( obj to_dealloc)

Destructor for obint.

Parameters
to_deallocAn obj pointer to an instance of obint with reference count of 0
Warning
Do not call manually, release will call automatically when the instances reference count drops to 0!
void obint_display ( const obj to_print)

Descriptor for an instance of obint, prints relevant information about the class to stderr.

Parameters
to_printA non-NULL obj pointer to an instance of type obint
ob_hash_t obint_hash ( const obj to_hash)

Hash function for obint.

Parameters
to_hashAn obj pointer to an instance of obint
Returns
Key value (hash) for the given obj pointer to a obint
int64_t obint_magnitude ( const obint a)

Returns the unsigned value of the obint.

Parameters
aA non-NULL pointer to type obint
Returns
a positive int64_t representing the value of the argument 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.

Parameters
aA non-NULL pointer to type obint
Returns
An integer index where the most significant non-zero digit in a can be found
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.

Parameters
aA non-NULL pointer to type obint
bA non-NULL pointer to type obint
Returns
An instance of obint, which may or may not have proper sign

Multiplication performed using the Karatsuba multiplcation algorithm

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.

Parameters
aA non-NULL pointer to type obint
bA non-NULL pointer to type obint
approxA non-NULL pointer to type obint used to accumulate a quotient value
quotientA boolean value, 0 indicates that a remainder should be returned, non-zero indicates a quotient should be returned
Returns
An instance of obint, which may or may not have proper sign
void obint_set_max_digits ( uint8_t  digits)

Sets the number of digits operated on in a primitive from 1 to 17.

Parameters
digitsAn integer between 2 and 17 inclusive
Warning
If digits does not fall in the 2 to 17 inclusive range nothing is done
The default value of 17 is most efficient, this method exists for testing purposes only!
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

Parameters
aA non-NULL pointer to type obint
mNumber of digits to shift
void obint_split ( const obint a,
uint64_t  i,
obint **  b1,
obint **  b0 
)

Splits the obint into two obint instances at given index.

Parameters
aA non-NULL pointer to type obint to be split
iThe integer index where the split occurs, where a-digits[i] is placed in the most significant section of the split
b1A reference to a pointer to type obint, used to return the most significant section of the obint being split
b0A 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

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.

Parameters
aA non-NULL pointer to type obint, larger or equal to b
bA non-NULL pointer to type obint, smaller or equal to a
Returns
An instance of obint, which may or may not have proper sign
Warning
Proper results guaranteed only for a >= b, a < b will not work and probably will cause segmentation faults