Project Euler Solutions
Bcd_operators

The functions that implement math operators using only BCD_int objects. More...

comp_t BCD_int::cmp_bcd (const BCD_int x, const BCD_int y)
 Compare two BCD_ints. More...
 
BCD_int 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 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 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 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 BCD_int::add_bcd (const BCD_int x, const BCD_int y)
 Add two BCD_ints. More...
 
BCD_int BCD_int::inc_bcd (const BCD_int x)
 Increment a BCD_int. More...
 
BCD_int BCD_int::sub_bcd (const BCD_int x, const BCD_int y)
 Subtract two BCD_ints. More...
 
BCD_int BCD_int::dec_bcd (const BCD_int x)
 Decrement a BCD_int. More...
 
BCD_int BCD_int::mul_bcd (const BCD_int x, const BCD_int y)
 Multiply two BCD_ints. More...
 
BCD_int BCD_int::div_bcd (const BCD_int x, const BCD_int y)
 Divide two BCD_ints. More...
 
BCD_int BCD_int::mod_bcd (const BCD_int x, const BCD_int y)
 Modulo divide two BCD_ints. More...
 
BCD_int BCD_int::divmod_bcd (const BCD_int x, BCD_int y, BCD_int *mod)
 Divide and modulo divide two BCD_ints. More...
 
BCD_int BCD_int::pow_bcd (const BCD_int x, const BCD_int y)
 Raise x to the power of y. More...
 
BCD_int BCD_int::factorial_bcd (const BCD_int x)
 Get the factorial of x. More...
 

Detailed Description

The functions that implement math operators using only BCD_int objects.

operators

Function Documentation

BCD_int abs_bcd ( const BCD_int  x,
const bool  no_copy 
)

Get the absolute value of a BCD_int without relying on internals.

Parameters
[in]xThe BCD_int in question
[in]no_copyIf false, this function returns a modified copy of x instead of a modified version of x
Returns
Either a positive copy of x or a positive version of x
Remarks
This will take \(Θ(1)\) time if no_copy is true, and \(Θ(\log_{100}(x))\) if it is false.
Attention
All operators that return a BCD_int may return NaN with error set to NO_MEM (avoid with no_copy)
All operators that return a BCD_int will return NaN if fed NaN, and set error to {OP}_NAN.
See also
sign_bcd
BCD_int add_bcd ( const BCD_int  x,
const BCD_int  y 
)

Add two BCD_ints.

Parameters
[in]xThe left-hand BCD_int
[in]yThe right-hand BCD_int
Returns
A BCD_int reflecting the sum of the arguments
Remarks
This will take \(O(\log_{100}(max(x, y)))\) time
Note
Implementation details:
This function works closely with sub_bcd. If absolute value would go down from this operation, it is handed off to that method.
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:

comp_t cmp_bcd ( const BCD_int  x,
const BCD_int  y 
)

Compare two BCD_ints.

Parameters
[in]xThe left-hand BCD_int
[in]yThe right-hand BCD_int
Returns
An comp_t reflecting the comparison
Return values
BCD_int dec_bcd ( const BCD_int  x)

Decrement a BCD_int.

Parameters
[in]xThe BCD_int to decrement
Returns
A BCD_int one less than x
Remarks
This will take \(Θ(\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.
See also
sub_bcd
BCD_int div_bcd ( const BCD_int  x,
const BCD_int  y 
)

Divide two BCD_ints.

Parameters
[in]xThe left-hand BCD_int
[in]yThe right-hand BCD_int
Returns
A BCD_int reflecting the quotient of the arguments
Remarks
See also
divmod_bcd for a performance analysis
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.
Returns NaN with error set to DIV_ZERO if y is 0

Here is the caller graph for this function:

BCD_int divmod_bcd ( const BCD_int  x,
BCD_int  y,
BCD_int mod 
)

Divide and modulo divide two BCD_ints.

Parameters
[in]xThe left-hand BCD_int
[in]yThe right-hand BCD_int
[out]modA pointer to the BCD_int you would like to store the remainder
Returns
A BCD_int reflecting the quotient of the arguments
Remarks
This function has three behaviors for performance analysis
  • If x or y is NaN, or y is 0, then it will take \(Θ(1)\) time
  • If y is 1, then it will take \(Θ(\log_{100}(x))\) time
  • Otherwise it will take \(O(\lceil\frac{x}{y}\rceil \cdot \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.
Returns (and assigns to mod) NaN with error set to DIV_ZERO if y is 0
BCD_int factorial_bcd ( const BCD_int  x)

Get the factorial of x.

Parameters
[in]xThe BCD_int in question
Returns
A BCD_int reflecting the factorial of x
Remarks
This will take \(O(x \cdot \log_{100}(x!)^3)\) time if x is not BCD_nan and is non-negative. Otherwise it takes \(Θ(1)\) 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.
Returns NaN with error set to FACT_NEG if x < 0
BCD_int inc_bcd ( const BCD_int  x)

Increment a BCD_int.

Parameters
[in]xThe BCD_int to increment
Returns
A BCD_int one greater than x
Remarks
This will take \(Θ(\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.
See also
add_bcd
BCD_int mod_bcd ( const BCD_int  x,
const BCD_int  y 
)

Modulo divide two BCD_ints.

Parameters
[in]xThe left-hand BCD_int
[in]yThe right-hand BCD_int
Returns
A BCD_int reflecting the remainder of the arguments
Remarks
This function has two behaviors for performance analysis
  • If x or y is NaN, or y is either 0 or 1, then it will take \(Θ(1)\) time
  • Otherwise it will take \(O(\lceil\frac{x}{y}\rceil \cdot \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.
Returns NaN with error set to DIV_ZERO if y is 0

Here is the caller graph for this function:

BCD_int mul_bcd ( const BCD_int  x,
const BCD_int  y 
)

Multiply two BCD_ints.

Parameters
[in]xThe left-hand BCD_int
[in]yThe right-hand BCD_int
Returns
A BCD_int reflecting the product of the arguments
Remarks
This will take \(Θ(\log_{100}(x) \cdot \log_{100}(y) \cdot \log{100}(xy))\) time if x and y are neither BCD_nan nor zero. Otherwise it takes \(Θ(1)\) time. For most purposes this can be simplified to \(O(\log_{100}^3(max(x, 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 neg_bcd ( const BCD_int  x,
const bool  no_copy 
)

Get the negative absolute value of a BCD_int without relying on internals.

Parameters
[in]xThe BCD_int in question
[in]no_copyIf false, this function returns a modified copy of x instead of a modified version of x
Returns
Either a negative copy of x or a negative version of x
Remarks
This will take \(Θ(1)\) time if no_copy is true, and \(Θ(\log_{100}(x))\) if it is false.
Attention
All operators that return a BCD_int may return NaN with error set to NO_MEM (avoid with no_copy)
All operators that return a BCD_int will return NaN if fed NaN, and set error to {OP}_NAN.
See also
sign_bcd
BCD_int opp_bcd ( const BCD_int  x,
const bool  no_copy 
)

Get the opposite value of a BCD_int without relying on internals.

Parameters
[in]xThe BCD_int in question
[in]no_copyIf false, this function returns a modified copy of x instead of a modified version of x
Returns
Either an opposite copy of x or an opposite version of x
Remarks
This will take \(Θ(1)\) time if no_copy is true, and \(Θ(\log_{100}(x))\) if it is false.
Attention
All operators that return a BCD_int may return NaN with error set to NO_MEM (avoid with no_copy)
All operators that return a BCD_int will return NaN if fed NaN, and set error to {OP}_NAN.
See also
sign_bcd
BCD_int pow_bcd ( const BCD_int  x,
const BCD_int  y 
)

Raise x to the power of y.

Parameters
[in]xThe left-hand BCD_int
[in]yThe right-hand BCD_int
Returns
A BCD_int reflecting the yth power of x
Remarks
If x and y are BCD_nan or y is not positive, this takes \(Θ(1)\) time. Otherwise it takes \(O((y \cdot \log_100(x))^3)\) 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.
Returns NaN with error set to POW_NEG if y < 0 or x = 0

Here is the caller graph for this function:

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.

Parameters
[in]xThe BCD_int in question
[in]no_copyIf false, this function returns a modified copy of x instead of a modified version of x
[in]negativeThe sign you would like to apply
Returns
Either a modified copy of x or a modified version of x
Remarks
This will take \(Θ(1)\) time if no_copy is true, and \(Θ(\log_{100}(x))\) if it is false.
Attention
All operators that return a BCD_int may return NaN with error set to NO_MEM (avoid with no_copy)
All operators that return a BCD_int will return NaN if fed NaN, and set error to {OP}_NAN.
BCD_int sub_bcd ( const BCD_int  x,
const BCD_int  y 
)

Subtract two BCD_ints.

Parameters
[in]xThe left-hand BCD_int
[in]yThe right-hand BCD_int
Returns
A BCD_int reflecting the difference of the arguments
Remarks
This will take \(O(\log_{100}(max(x, y)))\) time
Note
Implementation details:
This function works closely with add_bcd. If absolute value would go up from this operation, it is handed off to that method.
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: