Project Euler Solutions
Public Attributes | List of all members
BCD_int Struct Reference

A little-endian, arbitrary-precision, binary-coded-decimal number. More...

#include <bcd.h>

Public Member Functions

void free_BCD_int (BCD_int *const x)
 if x is not constant, this sets all flags to 0, frees used memory, sets nan to true, and error to IS_FREED More...
 
BCD_int new_BCD_int1 (const intmax_t a)
 
BCD_int new_BCD_int2 (uintmax_t a, const bool negative)
 
BCD_int copy_BCD_int (BCD_int a)
 
BCD_int BCD_from_bytes (const unsigned char *const str, const size_t chars, const bool negative, const bool little_endian)
 
BCD_int BCD_from_ascii (const char *const str, const size_t digits, const bool negative)
 
BCD_int bcd_error (const BCD_error error, const BCD_error orig_error)
 A shorthand way of making a BCD_int error object. More...
 
comp_t cmp_bcd (const BCD_int x, const BCD_int y)
 Compare two BCD_ints. More...
 
BCD_int sign_bcd (BCD_int x, const bool no_copy, const bool negative)
 Change the sign of a BCD_int without relying on internals. More...
 
BCD_int abs_bcd (const BCD_int x, const bool no_copy)
 Get the absolute value of a BCD_int without relying on internals. More...
 
BCD_int neg_bcd (const BCD_int x, const bool no_copy)
 Get the negative absolute value of a BCD_int without relying on internals. More...
 
BCD_int opp_bcd (const BCD_int x, const bool no_copy)
 Get the opposite value of a BCD_int without relying on internals. More...
 
BCD_int add_bcd (const BCD_int x, const BCD_int y)
 Add two BCD_ints. More...
 
BCD_int inc_bcd (const BCD_int x)
 Increment a BCD_int. More...
 
BCD_int sub_bcd (const BCD_int x, const BCD_int y)
 Subtract two BCD_ints. More...
 
BCD_int dec_bcd (const BCD_int x)
 Decrement a BCD_int. More...
 
BCD_int mul_bcd (const BCD_int x, const BCD_int y)
 Multiply two BCD_ints. More...
 
BCD_int div_bcd (const BCD_int x, const BCD_int y)
 Divide two BCD_ints. More...
 
BCD_int mod_bcd (const BCD_int x, const BCD_int y)
 Modulo divide two BCD_ints. More...
 
BCD_int divmod_bcd (const BCD_int x, BCD_int y, BCD_int *mod)
 Divide and modulo divide two BCD_ints. More...
 
BCD_int pow_bcd (const BCD_int x, const BCD_int y)
 Raise x to the power of y. More...
 
BCD_int factorial_bcd (const BCD_int x)
 Get the factorial of x. More...
 
void isign_bcd (BCD_int *const x, const bool negative)
 Change the sign of a BCD_int without relying on internals. More...
 
void iabs_bcd (BCD_int *const x)
 Get the absolute value of a BCD_int without relying on internals. More...
 
void ineg_bcd (BCD_int *const x)
 Get the negative absolute value of a BCD_int without relying on internals. More...
 
void iopp_bcd (BCD_int *const x)
 Get the opposite value of a BCD_int without relying on internals. More...
 
void iadd_bcd (BCD_int *const x, const BCD_int y)
 Add two BCD_ints and assign the result to x. More...
 
void iinc_bcd (BCD_int *const x)
 Increment a BCD_int and assign the result to x. More...
 
void isub_bcd (BCD_int *const x, const BCD_int y)
 Subtract two BCD_ints and assign the result to x. More...
 
void idec_bcd (BCD_int *const x)
 Decrement a BCD_int and assign the result to x. More...
 
void imul_bcd (BCD_int *const x, const BCD_int y)
 Multiply two BCD_ints and assign the result to x. More...
 
void idiv_bcd (BCD_int *const x, const BCD_int y)
 Divide two BCD_ints and assign the result to x. More...
 
void imod_bcd (BCD_int *const x, const BCD_int y)
 Modulo divide two BCD_ints and assign the result to x. More...
 
void idivmod_bcd (BCD_int *const x, BCD_int *const y)
 Divide two BCD_ints then assign the quotient to x and remainder to y. More...
 
void ipow_bcd (BCD_int *const x, const BCD_int y)
 Raise x to the power of y then assign the result to x. More...
 
void ifactorial_bcd (BCD_int *const x)
 Get the factorial of x then assign the result to x. More...
 
uintmax_t abs_bcd_cuint (const BCD_int x)
 Attempt to get the C-style absolute value of x. More...
 
intmax_t val_bcd_cint (const BCD_int x)
 Attempt to get the C-style signed representation of x. More...
 
comp_t cmp_bcd_cint (const BCD_int x, const intmax_t y)
 compare a BCD_int with a C-style signed integer More...
 
comp_t cmp_bcd_cuint (const BCD_int x, const uintmax_t y)
 compare a BCD_int with a C-style unsigned integer More...
 
BCD_int mul_bcd_cint (const BCD_int x, const intmax_t y)
 Multiply a BCD_int by a C-style signed integer. More...
 
BCD_int mul_bcd_cuint (const BCD_int x, uintmax_t y)
 Multiply a BCD_int by a C-style unsigned integer. More...
 
BCD_int mul_bcd_pow_10 (const BCD_int x, const size_t tens)
 Multiply a BCD_int by a power of ten. More...
 
BCD_int shift_bcd_left (const BCD_int a, const size_t tens)
 Multiply a BCD_int by a power of ten. More...
 
BCD_int div_bcd_pow_10 (const BCD_int x, const size_t tens)
 Divide a BCD_int by a power of ten. More...
 
BCD_int shift_bcd_right (const BCD_int a, const size_t tens)
 Divide a BCD_int by a power of ten. More...
 
BCD_int pow_cint_cuint (const intmax_t x, uintmax_t y)
 Raise a C-style integer to the power of another C-style signed integer. More...
 
BCD_int pow_cuint_cuint (const uintmax_t x, uintmax_t y)
 Raise a C-style integer to the power of another C-style unsigned integer. More...
 
void imul_bcd_cint (BCD_int *const x, const intmax_t y)
 Multiply in-place a BCD_int by a C-style signed integer. More...
 
void imul_bcd_cuint (BCD_int *const x, const uintmax_t y)
 Multiply in-place a BCD_int by a C-style unsigned integer. More...
 
void imul_bcd_pow_10 (BCD_int *const x, const size_t tens)
 Multiply in-place a BCD_int by a power of ten. More...
 
void ishift_bcd_left (BCD_int *const a, const size_t tens)
 Multiply in-place a BCD_int by a power of ten. More...
 
void idiv_bcd_pow_10 (BCD_int *const x, const size_t tens)
 Divide in-place a BCD_int by a power of ten. More...
 
void ishift_bcd_right (BCD_int *const a, const size_t tens)
 Divide in-place a BCD_int by a power of ten. More...
 
void print_bcd (const BCD_int x)
 Print a BCD_int to the screen. More...
 
void print_bcd_ln (const BCD_int x)
 Print a BCD_int to the screen and append a newline. More...
 

Public Attributes

packed_BCD_pair * data
 the raw data of the integer, DO NOT modify directly More...
 
size_t bcd_digits
 the byte count of data More...
 
size_t decimal_digits
 the number of decimal digits in this integer More...
 
union {
   uint8_t   nan
 indicates that the integer is NaN More...
 
}; 
 
bool negative: 1
 indicates the integer is negative More...
 
bool zero: 1
 indicates the integer is 0 More...
 
bool even: 1
 indicates the integer is even More...
 
bool constant: 1
 indicates that the integer is a constant and will not be touched by free_bcd_int() More...
 

Detailed Description

A little-endian, arbitrary-precision, binary-coded-decimal number.

Member Data Documentation

union { ... }
size_t BCD_int::bcd_digits

the byte count of data

bool BCD_int::constant

indicates that the integer is a constant and will not be touched by free_bcd_int()

packed_BCD_pair* BCD_int::data

the raw data of the integer, DO NOT modify directly

size_t BCD_int::decimal_digits

the number of decimal digits in this integer

bool BCD_int::even

indicates the integer is even

uint8_t BCD_int::nan

indicates that the integer is NaN

bool BCD_int::negative

indicates the integer is negative

bool BCD_int::zero

indicates the integer is 0


The documentation for this struct was generated from the following file: