33#include "rounding.hpp"
35#include "types/rounding.hpp"
63 template<__
internals::utils::StringLiteral fnName>
80 output::warning(std::string(fnName.value),
"Invalid precision specified"s);
97 template<concepts::Numeric ValueT>
103 void set(std::string newVal) {
value = std::move(newVal); }
277 [[nodiscard]] std::string
present()
const;
297 inline Number operator""_n(
long double value) {
return Number(value); }
299 inline Number operator""_n(
unsigned long long value) {
return Number(value); }
Represents a number with arbitrary precision. It basically stores the value as a string.
Definition number.hpp:53
bool operator>=(const Number &rhs) const
Compares two numbers for greater than or equal to.
Definition number.cpp:138
Number operator*(const Number &rhs) const
Multiplies two numbers.
Definition number.cpp:59
Number & operator*=(const Number &rhs)
Multiplies the number by another number and assigns the result to the current number.
Definition number.cpp:102
bool operator<=(const Number &rhs) const
Compares two numbers for less than or equal to.
Definition number.cpp:136
Number & operator%=(const Number &rhs)
Calculates the remainder of two numbers and assigns the result to the current number.
Definition number.cpp:116
size_t prec
The precision of the number.
Definition number.hpp:58
bool operator<(const Number &rhs) const
Compares two numbers for less than.
Definition number.cpp:132
bool operator!=(const Number &rhs) const
Compares two numbers for inequality.
Definition number.cpp:130
Number(std::string value="0", size_t prec=10, RoundingMode mode=RoundingMode::USE_CURRENT_PREC)
Initializes a number with a specified value.
Definition number.cpp:50
bool operator>(const Number &rhs) const
Compares two numbers for greater than.
Definition number.cpp:134
Number operator--()
Decrements the number by one.
Definition number.cpp:156
Number & operator^=(const Number &rhs)
Raises the number to a power and assigns the result to the current number.
Definition number.cpp:122
Number & operator-=(const Number &rhs)
Subtracts the number from another number and assigns the result to the current number.
Definition number.cpp:95
Number mod(const Number &rhs) const
Takes a modulus operation.
Definition number.cpp:78
Number operator++()
Increments the number by one.
Definition number.cpp:150
Number operator%(const Number &rhs) const
Calculates the remainder of two numbers. (Modulus)
Definition number.cpp:73
Number & operator/=(const Number &rhs)
Divides the number by another number and assigns the result to the current number.
Definition number.cpp:109
std::string value
The value of the number.
Definition number.hpp:55
Number(ValueT value, size_t prec=10, RoundingMode mode=RoundingMode::USE_CURRENT_PREC)
Initializes a number with a C/C++ long double value.
Definition number.hpp:98
RoundingMode mode
The rounding mode of the number.
Definition number.hpp:61
Number operator+() const
Unary plus operator.
Definition number.cpp:148
std::string present() const
Presents the number in a human-readable format.
Definition number.cpp:162
size_t determinePrec(const Number &rhs) const
Definition number.hpp:64
Number & operator+=(const Number &rhs)
Adds the number to another number and assigns the result to the current number.
Definition number.cpp:89
bool operator==(const Number &rhs) const
Compares two numbers for equality.
Definition number.cpp:128
Number abs() const
Gets the absolute value of the number.
Definition number.hpp:283
void set(std::string newVal)
Definition number.hpp:103
void setPrec(size_t newPrec, RoundingMode mode=RoundingMode::USE_CURRENT_PREC)
Definition number.hpp:105
Number operator-() const
Unary minus operator.
Definition number.cpp:140
Number operator/(const Number &rhs) const
Divides two numbers.
Definition number.cpp:66
Number operator^(const Number &rhs)
Raises the number to a power.
Definition number.cpp:83
std::string roundOff(const std::string &_number, const size_t digits, Rounding mode)
Round off a number to the nearest integer.
Definition rounding.cpp:60
Literal suffixes for literals to be converted to Steppable objects.
void warning(const std::basic_string< T > &name, const std::basic_string< T > &msg, const std::vector< std::string > &args={})
Prints a warning message.
Definition output.hpp:107
The public namespace for the Steppable library.
Definition argParse.cpp:40
RoundingMode
Specifies how Steppable should round the number in operations.
Definition rounding.hpp:34
@ DISCARD_ALL_DECIMALS
Do not append any decimal places.
Definition rounding.hpp:48
@ USE_MINIMUM_PREC
Use the lower precision whenever possible.
Definition rounding.hpp:39
@ USE_OTHER_PREC
Use the other number's precision.
Definition rounding.hpp:45
@ USE_MAXIMUM_PREC
Use the higher precision whenever possible.
Definition rounding.hpp:36
@ USE_CURRENT_PREC
Use the current precision.
Definition rounding.hpp:42
size_t operator()(const steppable::Number &n) const
Definition number.hpp:306