Steppable 0.0.1
A CAS project written from scratch in C++
|
Represents a number with arbitrary precision. It basically stores the value as a string. More...
#include <number.hpp>
Public Member Functions | |
Number (std::string value="0", size_t prec=10, RoundingMode mode=RoundingMode::USE_CURRENT_PREC) | |
Initializes a number with a specified value. | |
template<concepts::Numeric ValueT> | |
Number (ValueT value, size_t prec=10, RoundingMode mode=RoundingMode::USE_CURRENT_PREC) | |
Initializes a number with a C/C++ long double value. | |
void | set (std::string newVal) |
void | setPrec (size_t newPrec, RoundingMode mode=RoundingMode::USE_CURRENT_PREC) |
Number | operator+ (const Number &rhs) const |
Adds two numbers together. | |
Number | operator- (const Number &rhs) const |
Subtracts two numbers. | |
Number | operator* (const Number &rhs) const |
Multiplies two numbers. | |
Number | operator/ (const Number &rhs) const |
Divides two numbers. | |
Number | mod (const Number &rhs) const |
Takes a modulus operation. | |
Number | operator% (const Number &rhs) const |
Calculates the remainder of two numbers. (Modulus) | |
Number | operator^ (const Number &rhs) |
Raises the number to a power. | |
Number & | operator+= (const Number &rhs) |
Adds the number to another number and assigns the result to the current number. | |
Number & | operator-= (const Number &rhs) |
Subtracts the number from another number and assigns the result to the current number. | |
Number & | operator*= (const Number &rhs) |
Multiplies the number by another number and assigns the result to the current number. | |
Number & | operator/= (const Number &rhs) |
Divides the number by another number and assigns the result to the current number. | |
Number & | operator%= (const Number &rhs) |
Calculates the remainder of two numbers and assigns the result to the current number. | |
Number & | operator^= (const Number &rhs) |
Raises the number to a power and assigns the result to the current number. | |
bool | operator== (const Number &rhs) const |
Compares two numbers for equality. | |
bool | operator!= (const Number &rhs) const |
Compares two numbers for inequality. | |
bool | operator< (const Number &rhs) const |
Compares two numbers for less than. | |
bool | operator> (const Number &rhs) const |
Compares two numbers for greater than. | |
bool | operator<= (const Number &rhs) const |
Compares two numbers for less than or equal to. | |
bool | operator>= (const Number &rhs) const |
Compares two numbers for greater than or equal to. | |
Number | operator++ () |
Increments the number by one. | |
Number | operator-- () |
Decrements the number by one. | |
Number | operator- () const |
Unary minus operator. | |
Number | operator+ () const |
Unary plus operator. | |
std::string | present () const |
Presents the number in a human-readable format. | |
Number | abs () const |
Gets the absolute value of the number. |
Private Member Functions | |
template<__internals::utils::StringLiteral fnName> | |
size_t | determinePrec (const Number &rhs) const |
Private Attributes | |
std::string | value |
The value of the number. | |
size_t | prec |
The precision of the number. | |
RoundingMode | mode = RoundingMode::USE_CURRENT_PREC |
The rounding mode of the number. |
Represents a number with arbitrary precision. It basically stores the value as a string.
steppable::Number::Number | ( | std::string | value = "0", |
size_t | prec = 10, | ||
RoundingMode | mode = RoundingMode::USE_CURRENT_PREC ) |
Initializes a number with a specified value.
|
inline |
Initializes a number with a C/C++ long double value.
|
inlinenodiscard |
Gets the absolute value of the number.
|
inlinenodiscardprivate |
Takes a modulus operation.
Divides and takes the nearest quotient.
rhs | The other number. |
bool steppable::Number::operator!= | ( | const Number & | rhs | ) | const |
Compares two numbers for inequality.
rhs | The number to compare. |
Calculates the remainder of two numbers. (Modulus)
rhs | The number to divide. |
Calculates the remainder of two numbers and assigns the result to the current number.
rhs | The number to divide. |
Multiplies two numbers.
rhs | The number to multiply. |
Multiplies the number by another number and assigns the result to the current number.
rhs | The number to multiply. |
Number steppable::Number::operator+ | ( | ) | const |
Unary plus operator.
Does nothing. Simply returns a new instance of the number.
Adds two numbers together.
rhs | The number to add. |
Number steppable::Number::operator++ | ( | ) |
Increments the number by one.
Adds the number to another number and assigns the result to the current number.
rhs | The number to add. |
Number steppable::Number::operator- | ( | ) | const |
Unary minus operator.
Converts the number to itself with the opposite sign. Returns a new instance of the number.
Subtracts two numbers.
rhs | The number to subtract. |
Number steppable::Number::operator-- | ( | ) |
Decrements the number by one.
Subtracts the number from another number and assigns the result to the current number.
rhs | The number to subtract. |
Divides two numbers.
rhs | The number to divide. |
Divides the number by another number and assigns the result to the current number.
rhs | The number to divide. |
bool steppable::Number::operator< | ( | const Number & | rhs | ) | const |
Compares two numbers for less than.
rhs | The number to compare. |
bool steppable::Number::operator<= | ( | const Number & | rhs | ) | const |
Compares two numbers for less than or equal to.
rhs | The number to compare. |
bool steppable::Number::operator== | ( | const Number & | rhs | ) | const |
Compares two numbers for equality.
rhs | The number to compare. |
bool steppable::Number::operator> | ( | const Number & | rhs | ) | const |
Compares two numbers for greater than.
rhs | The number to compare. |
bool steppable::Number::operator>= | ( | const Number & | rhs | ) | const |
Compares two numbers for greater than or equal to.
rhs | The number to compare. |
Raises the number to a power.
rhs | The power to raise the number to. |
Raises the number to a power and assigns the result to the current number.
rhs | The power to raise the number to. |
|
nodiscard |
Presents the number in a human-readable format.
|
inline |
|
inline |
|
private |
The rounding mode of the number.
|
private |
The precision of the number.
|
private |
The value of the number.