Steppable 0.0.1
A CAS project written from scratch in C++
Loading...
Searching...
No Matches
number.hpp
1/**************************************************************************************************
2 * Copyright (c) 2023-2025 NWSOFT *
3 * *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy *
5 * of this software and associated documentation files (the "Software"), to deal *
6 * in the Software without restriction, including without limitation the rights *
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
8 * copies of the Software, and to permit persons to whom the Software is *
9 * furnished to do so, subject to the following conditions: *
10 * *
11 * The above copyright notice and this permission notice shall be included in all *
12 * copies or substantial portions of the Software. *
13 * *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
20 * SOFTWARE. *
21 **************************************************************************************************/
22
30
31#pragma once
32
33#include <string>
34
39namespace steppable
40{
62
67 class Number
68 {
69 private:
71 std::string value;
72
74 size_t prec;
75
78
79 public:
81 Number();
82
87 Number(std::string value = "0", size_t prec = 0, RoundingMode mode = USE_CURRENT_PREC);
88
94 Number operator+(const Number& rhs) const;
95
101 Number operator-(const Number& rhs) const;
102
108 Number operator*(const Number& rhs) const;
109
115 Number operator/(const Number& rhs) const;
116
122 Number operator%(const Number& rhs) const;
123
129 Number operator^(const Number& rhs) const;
130
136 Number& operator+=(const Number& rhs);
137
143 Number& operator-=(const Number& rhs);
144
150 Number& operator*=(const Number& rhs);
151
157 Number& operator/=(const Number& rhs);
158
164 Number& operator%=(const Number& rhs);
165
171 Number& operator^=(const Number& rhs);
172
178 bool operator==(const Number& rhs) const;
179
185 bool operator!=(const Number& rhs) const;
186
192 bool operator<(const Number& rhs) const;
193
199 bool operator>(const Number& rhs) const;
200
206 bool operator<=(const Number& rhs) const;
207
213 bool operator>=(const Number& rhs) const;
214
220
226
231 [[nodiscard]] std::string present() const;
232 };
233} // namespace steppable
bool operator>=(const Number &rhs) const
Compares two numbers for greater than or equal to.
Definition number.cpp:128
Number operator*(const Number &rhs) const
Multiplies two numbers.
Definition number.cpp:55
Number & operator*=(const Number &rhs)
Multiplies the number by another number and assigns the result to the current number.
Definition number.cpp:94
bool operator<=(const Number &rhs) const
Compares two numbers for less than or equal to.
Definition number.cpp:126
Number & operator%=(const Number &rhs)
Calculates the remainder of two numbers and assigns the result to the current number.
Definition number.cpp:106
size_t prec
The precision of the number.
Definition number.hpp:74
bool operator<(const Number &rhs) const
Compares two numbers for less than.
Definition number.cpp:122
bool operator!=(const Number &rhs) const
Compares two numbers for inequality.
Definition number.cpp:120
bool operator>(const Number &rhs) const
Compares two numbers for greater than.
Definition number.cpp:124
Number operator--()
Decrements the number by one.
Definition number.cpp:136
Number & operator^=(const Number &rhs)
Raises the number to a power and assigns the result to the current number.
Definition number.cpp:112
Number & operator-=(const Number &rhs)
Subtracts the number from another number and assigns the result to the current number.
Definition number.cpp:88
Number operator++()
Increments the number by one.
Definition number.cpp:130
Number operator%(const Number &rhs) const
Calculates the remainder of two numbers. (Modulus)
Definition number.cpp:78
Number & operator/=(const Number &rhs)
Divides the number by another number and assigns the result to the current number.
Definition number.cpp:100
std::string value
The value of the number.
Definition number.hpp:71
RoundingMode mode
The rounding mode of the number.
Definition number.hpp:77
Number()
The default constructor. Initializes the number with a value of 0.
Definition number.cpp:45
std::string present() const
Presents the number in a human-readable format.
Definition number.cpp:142
Number operator+(const Number &rhs) const
Adds two numbers together.
Definition number.cpp:51
Number & operator+=(const Number &rhs)
Adds the number to another number and assigns the result to the current number.
Definition number.cpp:82
bool operator==(const Number &rhs) const
Compares two numbers for equality.
Definition number.cpp:118
Number operator^(const Number &rhs) const
Raises the number to a power.
Definition number.cpp:80
Number operator-(const Number &rhs) const
Subtracts two numbers.
Definition number.cpp:53
Number operator/(const Number &rhs) const
Divides two numbers.
Definition number.cpp:57
The public namespace for the Steppable library.
Definition argParse.cpp:40
RoundingMode
Specifies how Steppable should round the number in operations.
Definition number.hpp:46
@ DISCARD_ALL_DECIMALS
Do not append any decimal places.
Definition number.hpp:60
@ USE_CURRENT_PREC
Use the current precision.
Definition number.hpp:54
@ USE_OTHER_PREC
Use the other number's precision.
Definition number.hpp:57
@ USE_MINIMUM_PREC
Use the lower precision whenever possible.
Definition number.hpp:51
@ USE_MAXIMUM_PREC
Use the higher precision whenever possible.
Definition number.hpp:48
Untitled