|
2 | 2 | export module math:numbers.general; |
3 | 3 |
|
4 | 4 | import std; |
| 5 | + |
5 | 6 | import :general; |
| 7 | + |
6 | 8 | import math.ops; |
7 | 9 | import math.symbols; |
8 | 10 |
|
9 | 11 | export namespace zero::math { |
10 | | - template<typename Derived> |
| 12 | + template<typename Derived> // can't constraint it with Number since ATM only fwd decls |
11 | 13 | class NumberBase { |
12 | 14 | // TODO: ensure in our concept (or create another) that all the Number(s) contains |
13 | 15 | // a fixed name member (like _value or _number), normalized, so we can access it |
14 | 16 | private: |
15 | 17 | friend Derived; |
16 | 18 | NumberBase() = default; |
17 | 19 |
|
18 | | - auto _self() -> Derived& { |
| 20 | + inline constexpr auto _self() -> Derived& { |
19 | 21 | return static_cast<Derived&>(*this); |
20 | 22 | } |
21 | 23 |
|
22 | | - auto _self() const -> const Derived& { |
| 24 | + inline constexpr auto _self() const -> const Derived& { |
23 | 25 | return static_cast<const Derived&>(*this); |
24 | 26 | } |
25 | 27 | public: |
26 | 28 | // Addition |
27 | | - [[nodiscard]] Derived operator+(const Derived& rhs) const noexcept { |
| 29 | + [[nodiscard]] constexpr auto operator+(const Derived& rhs) const noexcept -> Derived { |
28 | 30 | return Derived(_self().number() + rhs.number()); |
29 | 31 | } |
30 | 32 |
|
31 | 33 | // Subtraction |
32 | | - [[nodiscard]] Derived operator-(const Derived& rhs) const noexcept { |
| 34 | + [[nodiscard]] constexpr auto operator-(const Derived& rhs) const noexcept -> Derived { |
33 | 35 | return Derived(_self().number() - rhs.number()); |
34 | 36 | } |
35 | 37 |
|
36 | 38 | // Multiplication |
37 | | - [[nodiscard]] Derived operator*(const Derived& rhs) const noexcept { |
| 39 | + [[nodiscard]] constexpr auto operator*(const Derived& rhs) const noexcept -> Derived { |
38 | 40 | return Derived(_self().number() * rhs.number()); |
39 | 41 | } |
40 | 42 |
|
41 | 43 | // Division |
42 | | - [[nodiscard]] Derived operator/(const Derived& rhs) const noexcept { |
| 44 | + // TODO: removed the noexcept, since division by Zero must return std::expect or just throw |
| 45 | + [[nodiscard]] constexpr auto operator/(const Derived& rhs) const -> Derived { |
43 | 46 | return Derived(_self().number() / rhs.number()); |
44 | 47 | } |
45 | 48 |
|
46 | | - [[nodiscard]] constexpr bool operator==(const Derived& rhs) const noexcept { |
| 49 | + [[nodiscard]] constexpr auto operator==(const Derived& rhs) const noexcept -> Derived { |
47 | 50 | return _self().number() == rhs.number(); |
48 | 51 | } |
49 | 52 | }; |
|
0 commit comments