Steppable 0.0.1
A CAS project written from scratch in C++
Loading...
Searching...
No Matches
steppable::__internals::numUtils Namespace Reference

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.
 

Detailed Description

Utilities to operate numbers.

Function Documentation

◆ determineScale()

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.

Parameters
[in]numberThe number to be processed.
Returns
The scale of the number
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getFactors()

std::vector< std::string > steppable::__internals::numUtils::getFactors ( const std::string & _number)

Get the factors of a number.

Parameters
[in]_numberThe number to get the factors of.
Returns
The factors of the number.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getGreatestRootNum()

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.

Parameters
[in]_numberThe number to get the greatest root number of.
[in]baseThe base of the root.
Returns
The greatest root number less than or equal to the given number.
Here is the call graph for this function:

◆ getRootFactor()

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.

Parameters
[in]_numberThe number to get the largest root factor of.
[in]baseThe base of the root.
Returns
A result object containing the largest root factor of the number.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isDecimal()

bool steppable::__internals::numUtils::isDecimal ( const std::string & number)

Determines whether the number is a decimal or not.

Parameters
numberThe number.
Returns
False if it is an integer, true otherwise.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isEven()

bool steppable::__internals::numUtils::isEven ( const std::string & number)

Checks if a number is even.

Parameters
numberThe number to be checked.
Returns
True if the number is even, false otherwise.
Here is the call graph for this function:

◆ isInteger()

bool steppable::__internals::numUtils::isInteger ( const std::string & number)

Determines whether the number is an integer or not.

Parameters
numberThe number.
Returns
True if it is an integer, false otherwise.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isNumber()

bool steppable::__internals::numUtils::isNumber ( const std::string & s)

Checks if a given string is a valid number.

Parameters
[in]sThe string to be checked.
Returns
True if the string is a valid number, false otherwise.
Here is the caller graph for this function:

◆ isOdd()

bool steppable::__internals::numUtils::isOdd ( const std::string & number)

Checks if a number is odd.

Parameters
numberThe number to be checked.
Returns
True if the number is odd, false otherwise.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isPowerOfTen()

bool steppable::__internals::numUtils::isPowerOfTen ( const std::string & number)

Determines whether the number is a power of 10.

Parameters
numberThe number.
Returns
True if it is a power of 10, false otherwise.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isPrime()

bool steppable::__internals::numUtils::isPrime ( const std::string & _number)

Check if a number is prime.

Parameters
[in]_numberThe number to check.
Returns
True if the number is prime, false otherwise.
Here is the call graph for this function:

◆ isRoot()

ResultBool< std::string > steppable::__internals::numUtils::isRoot ( const std::string & _number,
const std::string & base )

Check if a number is a root number.

Parameters
[in]_numberThe number to check.
[in]baseThe base of the root.
Returns
StatusBool::CALCULATED_SIMPLIFIED_YES if the number is a root number, StatusBool::CALCULATED_SIMPLIFIED_NO otherwise.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isZeroString()

bool steppable::__internals::numUtils::isZeroString ( const std::string & string)
constexpr

Checks if a given string is a zero string.

A zero string is defined as a string that contains only the character '0'.

Parameters
[in]stringThe string to check.
Returns
True if the string is a zero string, false otherwise.
Here is the caller graph for this function:

◆ moveDecimalPlaces()

std::string steppable::__internals::numUtils::moveDecimalPlaces ( const std::string & _number,
long places )

Move the decimal places of a number.

Parameters
_numberThe number to process.
placesThe desired decimal places to move. A negative amount indicates moving to the left, while a positive amount indicates moving to the right.
Returns
The processed number.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeLeadingZeros() [1/2]

auto steppable::__internals::numUtils::removeLeadingZeros ( const std::string & string) -> std::decay_t< decltype(string)>

Removes leading zeros from a string.

Parameters
[in]stringThe input string.
Returns
The string with leading zeros removed.

◆ removeLeadingZeros() [2/2]

auto steppable::__internals::numUtils::removeLeadingZeros ( const std::vector< int > & vector) -> std::decay_t< decltype(vector)>

Removes leading zeros from a vector of integers.

Parameters
[in]vectorThe input vector.
Returns
The vector with leading zeros removed.
Here is the caller graph for this function:

◆ removeTrailingZeros() [1/2]

auto steppable::__internals::numUtils::removeTrailingZeros ( const std::string & numStr) -> std::decay_t< decltype(numStr)>

Removes trailing zeros from a string.

Parameters
[in]numStrThe input string.
Returns
The string with trailing zeros removed.

◆ removeTrailingZeros() [2/2]

auto steppable::__internals::numUtils::removeTrailingZeros ( const std::vector< int > & _vector) -> std::decay_t< decltype(_vector)>

Removes trailing zeros from a vector of integers.

Parameters
[in]_vectorThe input vector.
Returns
The vector with trailing zeros removed.
Here is the caller graph for this function:

◆ replaceLeadingZeros()

auto steppable::__internals::numUtils::replaceLeadingZeros ( const std::vector< int > & vector) -> std::decay_t< decltype(vector)>

Replaces leading zeros in the given vector with -2.

Parameters
[in]vectorThe vector to modify.
Returns
The modified vector with leading zeros replaced.

◆ roundDown()

std::string steppable::__internals::numUtils::roundDown ( const std::string & _number)

Round down a number to the nearest integer.

Parameters
[in]_numberThe number to round down.
Returns
The rounded number.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ roundOff()

std::string steppable::__internals::numUtils::roundOff ( const std::string & _number,
size_t digits = 0 )

Round off a number to the nearest integer.

Parameters
[in]_numberThe number to round.
[in]digitsThe number of decimal places to round to.
Returns
The rounded number.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ roundUp()

std::string steppable::__internals::numUtils::roundUp ( const std::string & _number)

Round up a number to the nearest integer.

Parameters
[in]_numberThe number to round up.
Returns
The rounded number.
Here is the call graph for this function:

◆ simplifyPolarity()

std::string steppable::__internals::numUtils::simplifyPolarity ( const std::string & _string)

Simplifies a string with non-standard polarity (e.g., –1, —1, etc.).

Parameters
[in]_stringA string to simplify.
Returns
A simplified string with correct polarity.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ simplifyZeroPolarity()

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".

Parameters
[in]stringThe input string to be simplified.
Returns
A simplified string with standard polarity.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ splitNumber()

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.

Parameters
[in]aThe first number as a string.
[in]bThe second number as a string.
[in]padIntegerFlag indicating whether to pad the integer part with spaces of the result.
[in]padDecimalFlag indicating whether to pad the decimal part with zeros of the result.
[in]properlyFormat
Returns
The result of splitting the two numbers.
See also
SplitNumberResult
Here is the call graph for this function:
Here is the caller graph for this function:

◆ standardizeNumber()

std::string steppable::__internals::numUtils::standardizeNumber ( const std::string & _number)

Standardizes a number string.

Parameters
[in]_numberThe number string to standardize.
Returns
The standardized number string.
Here is the call graph for this function:
Here is the caller graph for this function:
Untitled