Project Euler Solutions
Bcd_c_operators

The functions that implement math operators using at least some C-style integers. More...

uintmax_t BCD_int::abs_bcd_cuint (const BCD_int x)
 Attempt to get the C-style absolute value of x. More...
 
intmax_t BCD_int::val_bcd_cint (const BCD_int x)
 Attempt to get the C-style signed representation of x. More...
 
comp_t BCD_int::cmp_bcd_cint (const BCD_int x, const intmax_t y)
 compare a BCD_int with a C-style signed integer More...
 
comp_t BCD_int::cmp_bcd_cuint (const BCD_int x, const uintmax_t y)
 compare a BCD_int with a C-style unsigned integer More...
 
BCD_int 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 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 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 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 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 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 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 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...
 

Detailed Description

The functions that implement math operators using at least some C-style integers.

c_operators

Function Documentation

uintmax_t abs_bcd_cuint ( const BCD_int  x)

Attempt to get the C-style absolute value of x.

Parameters
[in]xThe BCD_int in question
Returns
Either the value of x OR -1 if x is NaN or |x| would overflow
Remarks
While this function techincally takes \(O(\log_{100}(x))\) time, x is limited on most systems to 64-bit values, so this function essentially runs in constant time ( \(Θ(1)\)).
comp_t cmp_bcd_cint ( const BCD_int  x,
const intmax_t  y 
)

compare a BCD_int with a C-style signed integer

Parameters
[in]xThe BCD_int in question
[in]yThe signed integer you would like to compare with
Returns
A comp_t indicating the difference between x and y
Remarks
While this function techincally takes \(O(\log_{100}(x))\) time, y is limited on most systems to 64-bit values, so this function essentially runs in constant time ( \(Θ(1)\)).
Note
Returns NO_COMP if x is NaN
See also
cmp_bcd
comp_t cmp_bcd_cuint ( const BCD_int  x,
const uintmax_t  y 
)

compare a BCD_int with a C-style unsigned integer

Parameters
[in]xThe BCD_int in question
[in]yThe signed integer you would like to compare with
Returns
A comp_t indicating the difference between x and y
Remarks
While this function techincally takes \(O(\log_{100}(x))\) time, y is limited on most systems to 64-bit values, so this function essentially runs in constant time ( \(Θ(1)\)).
Note
Returns NO_COMP if x is NaN
See also
cmp_bcd
BCD_int div_bcd_pow_10 ( const BCD_int  x,
const size_t  tens 
)

Divide a BCD_int by a power of ten.

Parameters
[in]xThe BCD_int you'd like to divide
[in]tensThe power of ten to divide by (in the form of \((10^{\texttt{tens}})\))
Returns
The result of \((x \div 10^{\texttt{tens}})\)
Remarks
This function takes \(Θ(\log_{100}(x))\) time
Warning
This function does not do true division, it simply trims digits. If you need true division, use div_bcd
As implemented, this function is equivalent to {int(str(x)[:-y])}. If you assume this is true division, you will get frequent off-by-one errors.
Attention
All operators that return a BCD_int may return NaN with error set to NO_MEM
All operators that return a BCD_int will return NaN if fed NaN, and set error to {OP}_NAN.
BCD_int mul_bcd_cint ( const BCD_int  x,
const intmax_t  y 
)

Multiply a BCD_int by a C-style signed integer.

Parameters
[in]xThe BCD_int in question
[in]yThe C-style integer to multiply by
Returns
The product of x and y
Attention
All operators that return a BCD_int may return NaN with error set to NO_MEM
All operators that return a BCD_int will return NaN if fed NaN, and set error to {OP}_NAN.
BCD_int mul_bcd_cuint ( const BCD_int  x,
uintmax_t  y 
)

Multiply a BCD_int by a C-style unsigned integer.

Parameters
[in]xThe BCD_int in question
[in]yThe C-style integer to multiply by
Returns
The product of x and y
Attention
All operators that return a BCD_int may return NaN with error set to NO_MEM
All operators that return a BCD_int will return NaN if fed NaN, and set error to {OP}_NAN.

Here is the caller graph for this function:

BCD_int mul_bcd_pow_10 ( const BCD_int  x,
const size_t  tens 
)

Multiply a BCD_int by a power of ten.

Parameters
[in]xThe BCD_int you'd like to multiply
[in]tensThe power of ten to multiply by (in the form of \((10^{\texttt{tens}})\))
Returns
The result of \((x \cdot 10^{\texttt{tens}})\)
Remarks
This function takes \(Θ(\log_{100}(x))\) time
Attention
All operators that return a BCD_int may return NaN with error set to NO_MEM
All operators that return a BCD_int will return NaN if fed NaN, and set error to {OP}_NAN.
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.

Parameters
[in]xThe base
[in]yThe exponent
Returns
The yth power of x in the form of a BCD_int
Attention
All operators that return a BCD_int may return NaN with error set to NO_MEM
All operators that return a BCD_int will return NaN if fed NaN, and set error to {OP}_NAN.
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.

Parameters
[in]xThe base
[in]yThe exponent
Returns
The yth power of x in the form of a BCD_int
Attention
All operators that return a BCD_int may return NaN with error set to NO_MEM
All operators that return a BCD_int will return NaN if fed NaN, and set error to {OP}_NAN.
BCD_int shift_bcd_left ( const BCD_int  a,
const size_t  tens 
)

Multiply a BCD_int by a power of ten.

Parameters
[in]aThe BCD_int you'd like to multiply
[in]tensThe power of ten to multiply by (in the form of \((10^{\texttt{tens}})\))
Returns
The result of \((x \cdot 10^{\texttt{tens}})\)
Remarks
This function takes \(Θ(\log_{100}(x))\) time
Attention
All operators that return a BCD_int may return NaN with error set to NO_MEM
All operators that return a BCD_int will return NaN if fed NaN, and set error to {OP}_NAN.
Note
This is just an alias for mul_bcd_pow_10

Here is the caller graph for this function:

BCD_int shift_bcd_right ( const BCD_int  a,
const size_t  tens 
)

Divide a BCD_int by a power of ten.

Parameters
[in]aThe BCD_int you'd like to divide
[in]tensThe power of ten to divide by (in the form of \((10^{\texttt{tens}})\))
Returns
The result of \((x \div 10^{\texttt{tens}})\)
Remarks
This function takes \(Θ(\log_{100}(x))\) time
Warning
This function does not do true division, it simply trims digits. If you need true division, use div_bcd
As implemented, this function is equivalent to {int(str(x)[:-y])}. If you assume this is true division, you will get frequent off-by-one errors.
Attention
All operators that return a BCD_int may return NaN with error set to NO_MEM
All operators that return a BCD_int will return NaN if fed NaN, and set error to {OP}_NAN.
Note
This is just an alias for div_bcd_pow_10

Here is the caller graph for this function:

intmax_t val_bcd_cint ( const BCD_int  x)

Attempt to get the C-style signed representation of x.

Parameters
[in]xThe BCD_int in question
Returns
Either the value of x OR INTMAX_MIN if x is NaN or |x| would overflow
Remarks
While this function techincally takes \(O(\log_{100}(x))\) time, x is limited on most systems to 64-bit values, so this function essentially runs in constant time ( \(Θ(1)\)).