Skip to content

c8_natural

Dave Hudson edited this page Apr 27, 2017 · 5 revisions

c8::natural

c8::natural is a class designed to represent the natural numbers (zero and all positive whole numbers). Conceptually they behave in a somewhat similar way to unsigned int, but offer unlimited precision.

Constructors

Construct a natural number.

Destructor

  • ~natural

Destroy (and free all resources allocated to) a natural number.

Comparison Operators

Compare this natural number with another.

Arithmetic Operators

Perform arithmetic with this number.

Bitwise Operators

Perform bitwise operations on this number.

Assignment Operators

Perform assignment operations on this number.

Sizing Member Function

Public Member Functions

  • auto divide_modulus(natural_digit v) const -> std::pair<natural, natural_digit>
  • auto divide_modulus(const natural &v) const -> std::pair<natural, natural>
  • auto gcd(const natural &v) const -> natural
  • auto to_unsigned_long_long() const -> unsigned long long
  • auto is_zero() const noexcept -> bool
  • friend auto operator <<(std::ostream &outstr, const natural &v) -> std::ostream &

TBD

Examples

c8::natural allows us to create two large numbers, subtract one from the other, then output the result to std::cout:

c8::natural s0("5872489572457574027439274027101850990940275827586671651690897");
c8::natural s1("842758978027689671615847509102945571507457514754190754");

auto s2 = s0 - s1;

std::cout << s2;
Clone this wiki locally