Skip to content

Commit

Permalink
chore: reordered the number concepts, so they are usable across all t…
Browse files Browse the repository at this point in the history
…he math module
  • Loading branch information
TheRustifyer committed Aug 31, 2024
1 parent 253917a commit 0a2d745
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export module math.numbers:numbers.concepts;
export module math:math.concepts;

import std;
import math.numbers;
import math.symbols;
import :general;

export namespace zero::math {
/// Concept to act as an interface for the abstract concept of 'number' in mathematics.
Expand All @@ -20,4 +20,11 @@ export namespace zero::math {
T::symbol; /* Check if 'T' has a static member named 'symbol' */
{ T::symbol } -> std::same_as<const MathSymbol&>; // Check if 'T::symbol' has the type MathSymbol
};

/**
* @brief Wrapper concept to constrain any kind of numerical types,
* both our {@link Number} concept or any C++ numerical primitive
*/
template <typename T>
concept Numerical = Number<T> || std::is_arithmetic_v<T>;
}
1 change: 1 addition & 0 deletions zero/ifc/math/math.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

export module math;

export import :math.concepts;
export import math.ops;
export import math.numbers;
export import math.symbols;
Expand Down
1 change: 0 additions & 1 deletion zero/ifc/math/numbers/integers.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import math.ops;
import math.symbols;

import :general;
import :numbers.concepts;
import :naturals;

export namespace zero::math {
Expand Down
1 change: 0 additions & 1 deletion zero/ifc/math/numbers/naturals.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import std;
import math.symbols;

import :general;
import :numbers.concepts;

export namespace zero::math {
/// A positive integer number
Expand Down
19 changes: 1 addition & 18 deletions zero/ifc/math/numbers/numbers.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,10 @@ import std;
import math.ops;
import math.symbols;

export import :numbers.concepts;
import :general;
import :detail;

export import :general;
export import :naturals;
export import :integers;
export import :rationals;

export namespace zero::math {
// TODO: Create individual concepts per Number type that allows to check more complex behaviour,
// like overflows (is this possible with a concept??!), that they can be constructible from certain types
// which allows us to reduce to only one template constructor per type instead of having lots of them

// class Real {
// double number; // TODO handle rationals and irrationals with std::variant?
// };
//
// class Complex {
// Real real;
// Real imaginary;
// };

}

2 changes: 0 additions & 2 deletions zero/ifc/math/numbers/rationals.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import math.ops;
import math.symbols;

import :general;
import :numbers.concepts;

import :naturals;
import :integers;

Expand Down
3 changes: 3 additions & 0 deletions zero/tests/math/numbers_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ TestSuite numbers_suite {"Numbers TS"};
/// Compile time tests for numbers
static_assert(Number<Natural>);
static_assert(Number<Integer>);
static_assert(Numerical<Integer>);
static_assert(Number<Rational>);
static_assert(!Number<int>);
static_assert(Numerical<int>);
static_assert(!Number<std::string>);

void numbers_tests() {
Expand Down
3 changes: 2 additions & 1 deletion zork_config/zork_local_linux.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ interfaces = [
{ file = 'math/linear_algebra/root.cppm', module_name = 'math.linear_algebra' },
# Numbers
{ file = 'math/numbers/general.cppm', partition = { module = 'math.numbers', partition_name = 'general' } },
{ file = 'math/numbers/numbers_concepts.cppm', partition = { module = 'math.numbers', partition_name = 'numbers.concepts' } },
{ file = 'math/numbers/naturals.cppm', partition = { module = 'math.numbers', partition_name = 'naturals' } },
{ file = 'math/numbers/integers.cppm', partition = { module = 'math.numbers', partition_name = 'integers' } },
{ file = 'math/numbers/rationals.cppm', partition = { module = 'math.numbers', partition_name = 'rationals' } },
{ file = 'math/numbers/detail.cpp', partition = { module = 'math.numbers', partition_name = 'detail', is_internal_partition = true } },
{ file = 'math/numbers/numbers.cppm', module_name = 'math.numbers' },
# Concepts
{ file = 'math/concepts.cppm', partition = { module = 'math', partition_name = 'math.concepts' } },
# Root
{ file = 'math/math.cppm' },

Expand Down

0 comments on commit 0a2d745

Please sign in to comment.