Steppable 0.0.1
A CAS project written from scratch in C++
|
Utilities to operate numbers. More...
Classes | |
struct | SplitNumberResult |
A structure for storing split numbers. More... | |
Functions | |
std::vector< std::string > | getFactors (const std::string &_number) |
Get the factors of a number. | |
ResultBool< std::string > | getRootFactor (const std::string &_number, const std::string &base="2") |
Get the largest factor of a number, that is a root number. | |
std::string | getGreatestRootNum (const std::string &_number, const std::string &base="2") |
Get the greatest root number less than or equal to the given number. | |
bool | isPrime (const std::string &_number) |
Check if a number is prime. | |
ResultBool< std::string > | isRoot (const std::string &_number, const std::string &base) |
Check if a number is a root number. | |
std::string | roundDown (const std::string &_number) |
Round down a number to the nearest integer. | |
std::string | roundUp (const std::string &_number) |
Round up a number to the nearest integer. | |
std::string | roundOff (const std::string &_number, size_t digits=0) |
Round off a number to the nearest integer. | |
std::string | moveDecimalPlaces (const std::string &_number, long places) |
Move the decimal places of a number. | |
bool | isNumber (const std::string &s) |
Checks if a given string is a valid number. | |
std::string | simplifyZeroPolarity (const std::string &string) |
Simplifies a string that represents a number with non-standard polarity. | |
std::string | simplifyPolarity (const std::string &_string) |
Simplifies a string with non-standard polarity (e.g., –1, —1, etc.). | |
std::string | standardizeNumber (const std::string &_number) |
Standardizes a number string. | |
SplitNumberResult | splitNumber (const std::string &_a, const std::string &_b, const bool padInteger, const bool padDecimal, bool properlyFormat, bool preserveNegative) |
auto | replaceLeadingZeros (const std::vector< int > &vector) -> std::decay_t< decltype(vector)> |
auto | removeLeadingZeros (const std::vector< int > &vector) -> std::decay_t< decltype(vector)> |
auto | removeLeadingZeros (const std::string &string) -> std::decay_t< decltype(string)> |
auto | removeTrailingZeros (const std::vector< int > &_vector) -> std::decay_t< decltype(_vector)> |
auto | removeTrailingZeros (const std::string &numStr) -> std::decay_t< decltype(numStr)> |
long long | determineScale (const std::string &number) |
Determines the scale of a number, i.e., the power of 10 when it is expressed in scientific notation. | |
bool | isInteger (const std::string &number) |
Determines whether the number is an integer or not. | |
bool | isDecimal (const std::string &number) |
Determines whether the number is a decimal or not. | |
bool | isPowerOfTen (const std::string &number) |
Determines whether the number is a power of 10. | |
bool | isOdd (const std::string &number) |
Checks if a number is odd. | |
bool | isEven (const std::string &number) |
Checks if a number is even. | |
constexpr bool | isZeroString (const std::string &string) |
Checks if a given string is a zero string. | |
Utilities to operate numbers.
long long steppable::__internals::numUtils::determineScale | ( | const std::string & | number | ) |
Determines the scale of a number, i.e., the power of 10 when it is expressed in scientific notation.
[in] | number | The number to be processed. |
std::vector< std::string > steppable::__internals::numUtils::getFactors | ( | const std::string & | _number | ) |
Get the factors of a number.
[in] | _number | The number to get the factors of. |
std::string steppable::__internals::numUtils::getGreatestRootNum | ( | const std::string & | _number, |
const std::string & | base = "2" ) |
Get the greatest root number less than or equal to the given number.
[in] | _number | The number to get the greatest root number of. |
[in] | base | The base of the root. |
ResultBool< std::string > steppable::__internals::numUtils::getRootFactor | ( | const std::string & | _number, |
const std::string & | base = "2" ) |
Get the largest factor of a number, that is a root number.
[in] | _number | The number to get the largest root factor of. |
[in] | base | The base of the root. |
bool steppable::__internals::numUtils::isDecimal | ( | const std::string & | number | ) |
Determines whether the number is a decimal or not.
number | The number. |
bool steppable::__internals::numUtils::isEven | ( | const std::string & | number | ) |
Checks if a number is even.
number | The number to be checked. |
bool steppable::__internals::numUtils::isInteger | ( | const std::string & | number | ) |
Determines whether the number is an integer or not.
number | The number. |
bool steppable::__internals::numUtils::isNumber | ( | const std::string & | s | ) |
Checks if a given string is a valid number.
[in] | s | The string to be checked. |
bool steppable::__internals::numUtils::isOdd | ( | const std::string & | number | ) |
Checks if a number is odd.
number | The number to be checked. |
bool steppable::__internals::numUtils::isPowerOfTen | ( | const std::string & | number | ) |
Determines whether the number is a power of 10.
number | The number. |
bool steppable::__internals::numUtils::isPrime | ( | const std::string & | _number | ) |
Check if a number is prime.
[in] | _number | The number to check. |
ResultBool< std::string > steppable::__internals::numUtils::isRoot | ( | const std::string & | _number, |
const std::string & | base ) |
Check if a number is a root number.
[in] | _number | The number to check. |
[in] | base | The base of the root. |
|
constexpr |
Checks if a given string is a zero string.
A zero string is defined as a string that contains only the character '0'.
[in] | string | The string to check. |
std::string steppable::__internals::numUtils::moveDecimalPlaces | ( | const std::string & | _number, |
long | places ) |
Move the decimal places of a number.
_number | The number to process. |
places | The desired decimal places to move. A negative amount indicates moving to the left, while a positive amount indicates moving to the right. |
auto steppable::__internals::numUtils::removeLeadingZeros | ( | const std::string & | string | ) | -> std::decay_t< decltype(string)> |
Removes leading zeros from a string.
[in] | string | The input string. |
auto steppable::__internals::numUtils::removeLeadingZeros | ( | const std::vector< int > & | vector | ) | -> std::decay_t< decltype(vector)> |
Removes leading zeros from a vector of integers.
[in] | vector | The input vector. |
auto steppable::__internals::numUtils::removeTrailingZeros | ( | const std::string & | numStr | ) | -> std::decay_t< decltype(numStr)> |
Removes trailing zeros from a string.
[in] | numStr | The input string. |
auto steppable::__internals::numUtils::removeTrailingZeros | ( | const std::vector< int > & | _vector | ) | -> std::decay_t< decltype(_vector)> |
Removes trailing zeros from a vector of integers.
[in] | _vector | The input vector. |
auto steppable::__internals::numUtils::replaceLeadingZeros | ( | const std::vector< int > & | vector | ) | -> std::decay_t< decltype(vector)> |
Replaces leading zeros in the given vector with -2.
[in] | vector | The vector to modify. |
std::string steppable::__internals::numUtils::roundDown | ( | const std::string & | _number | ) |
Round down a number to the nearest integer.
[in] | _number | The number to round down. |
std::string steppable::__internals::numUtils::roundOff | ( | const std::string & | _number, |
size_t | digits = 0 ) |
Round off a number to the nearest integer.
[in] | _number | The number to round. |
[in] | digits | The number of decimal places to round to. |
std::string steppable::__internals::numUtils::roundUp | ( | const std::string & | _number | ) |
Round up a number to the nearest integer.
[in] | _number | The number to round up. |
std::string steppable::__internals::numUtils::simplifyPolarity | ( | const std::string & | _string | ) |
Simplifies a string with non-standard polarity (e.g., –1, —1, etc.).
[in] | _string | A string to simplify. |
std::string steppable::__internals::numUtils::simplifyZeroPolarity | ( | const std::string & | string | ) |
Simplifies a string that represents a number with non-standard polarity.
This function takes a string that represents a number with a zero polarity and simplifies it to a standard polarity. E.g. "-0" is simplified to "0".
[in] | string | The input string to be simplified. |
SplitNumberResult steppable::__internals::numUtils::splitNumber | ( | const std::string & | a, |
const std::string & | b, | ||
bool | padInteger = true, | ||
bool | padDecimal = true, | ||
bool | properlyFormat = true, | ||
bool | preserveNegative = false ) |
Splits two numbers represented as strings and returns the result.
[in] | a | The first number as a string. |
[in] | b | The second number as a string. |
[in] | padInteger | Flag indicating whether to pad the integer part with spaces of the result. |
[in] | padDecimal | Flag indicating whether to pad the decimal part with zeros of the result. |
[in] | properlyFormat |
std::string steppable::__internals::numUtils::standardizeNumber | ( | const std::string & | _number | ) |
Standardizes a number string.
[in] | _number | The number string to standardize. |