Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The sets of numbers in mathematics #31

Draft
wants to merge 47 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
3e067ea
code: added quaternions and primes to the math symbols type
TheRustifyer Nov 9, 2023
3ae6ba9
code(WIP)!: initial implementation of the number sets, which up until…
TheRustifyer Nov 11, 2023
7459437
ci: removed the non ported yet tests using Catch2 to our test suite
TheRustifyer Nov 11, 2023
9681cc8
merged the latest changes from main, including the MathSymbol enumera…
TheRustifyer Nov 12, 2023
1859ab1
code: changed the types of the members, now they are Integers
TheRustifyer Nov 12, 2023
557a7fe
code(stylizer)!: refactored the whole file to apply the consistent id…
TheRustifyer Nov 12, 2023
9f4923a
code(numbers): Created the 'Number' concept to determine whenever a t…
TheRustifyer Nov 12, 2023
569e987
code(numbers): Created the 'Number' concept to determine whenever a t…
TheRustifyer Nov 13, 2023
683b461
code(numbers): Created the 'Number' concept to determine whenever a t…
TheRustifyer Nov 19, 2023
9501670
code(math.symbols): refactored the way on how this enum provides the …
TheRustifyer Nov 23, 2023
8e7f384
feat: Testing Zork++ v0.9.0 with native MSVC import std support
TheRustifyer May 26, 2024
f3373ff
feat: Normalizing the import of the C ISO std lib for working with Cl…
TheRustifyer May 27, 2024
372a271
fix: Correcting paths due to the new Zork++ standard way
TheRustifyer May 27, 2024
0db05f9
chore: Updated GitHub actions to use clang-16 and the Zork config fil…
TheRustifyer Aug 10, 2024
4f8094f
chore: Updated GitHub actions to use clang-16 only
TheRustifyer Aug 10, 2024
8b0e003
fix: wrong sign propagated on Rational addition and subtraction impl …
TheRustifyer Aug 10, 2024
cc688a3
feat: Rational type aritmetic multiplication
TheRustifyer Aug 12, 2024
5fd782b
chore: merged latest from main, changes to the output data of the tes…
TheRustifyer Aug 15, 2024
d61229b
Merge branch 'main' into development
TheRustifyer Aug 15, 2024
dda11a7
Merge branch 'numbers' into development
TheRustifyer Aug 15, 2024
186e77a
feat: overloads for the stylizer, so there's no need for std::initial…
TheRustifyer Aug 16, 2024
4c75dc8
Merge branch 'development' into numbers
TheRustifyer Aug 16, 2024
5c9f965
feat: Upgrading the project to be compatible with C++23 import std wi…
TheRustifyer Aug 21, 2024
c0d85b6
feat: Upgrading the Zork++ config to std C++23
TheRustifyer Aug 21, 2024
191fc42
chore: Gh tests Clang version 18.1.2
TheRustifyer Aug 21, 2024
f146626
chore: Gh tests Clang version 18
TheRustifyer Aug 21, 2024
9cd87d2
feat: LLVM suite on the GitHub actions
TheRustifyer Aug 21, 2024
f9e958e
chore: logging where APT installs the newly downloaded libc++
TheRustifyer Aug 21, 2024
951fda7
feat: Logging where are the installed std modules
TheRustifyer Aug 21, 2024
254668a
feat: Adding the installation of the LLVM-19 libc++ to the Zork++ cfg
TheRustifyer Aug 21, 2024
5fe2ed8
fix: Missing part of the path of libc++
TheRustifyer Aug 21, 2024
7257ade
feat: Removed a wrong -fmodules arg left by mistake
TheRustifyer Aug 21, 2024
e53d594
feat: 2b for now as the clang std lang level used by default
TheRustifyer Aug 21, 2024
d7ea7d1
feat: more remote configs
TheRustifyer Aug 21, 2024
8eaf98f
chore: more confs
TheRustifyer Aug 21, 2024
09181cf
Merge branch 'development' into numbers
TheRustifyer Aug 23, 2024
c54b12c
feat: cleaning zork confs and matrix imports
TheRustifyer Aug 23, 2024
a232c92
fix: wrong member name and removing std.compat when std::size_t is av…
TheRustifyer Aug 23, 2024
812a1ba
Merge branch 'development' into numbers
TheRustifyer Aug 24, 2024
06d3094
feat: merging latest from development and adding modern-ish C++23 swi…
TheRustifyer Aug 24, 2024
08d8726
Merge branch 'numbers' of https://github.com/ZeroDayCode/Zero into nu…
TheRustifyer Aug 26, 2024
7ae59b2
chore: merged fixes for the matrix type on branch 'msvc-native-import…
TheRustifyer Aug 26, 2024
d8b6f8a
feat: splitting the math numbers in module partitions
TheRustifyer Aug 27, 2024
179a588
feat: reworking the public API of Numbers in terms of the CRTP idiom
TheRustifyer Aug 30, 2024
253917a
feat: reordering the numbers/ folder acording to the new structure
TheRustifyer Aug 31, 2024
04d302d
chore: numbers module are now a partition of module math
TheRustifyer Sep 1, 2024
755487b
chore: moved concept Number to the general 'math' partition
TheRustifyer Sep 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CompileFlags: # Tweak the parse settings
Add: [-xc++, -Wall, -std=c++23, -stdlib=libc++, --target=x86_64-w64-windows-gnu] # treat all files as C++, enable more warnings
Remove: -W* # strip all other warning-related flags
Compiler: clang++ # Change argv[0] of compile flags to `clang++`
30 changes: 23 additions & 7 deletions .github/workflows/project_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,40 @@ jobs:
fail-fast: false
matrix:
include:
- { os: ubuntu-latest }
- { os: ubuntu-latest, clang_version: 19 }
# - { os: macos-latest }
# - { os: windows-latest }

steps:
- uses: actions/checkout@v3

- name: Clone Zork++
uses: GuillaumeFalourd/clone-github-repo-action@v2
uses: GuillaumeFalourd/clone-github-repo-action@v2.3
with:
owner: 'ZeroDayCode'
repository: 'Zork'
branch: 'feature/GH-127-clang-upgrades'

- name: Download the latest possible version of Clang
- name: Installing LLVM ${{ matrix.clang_version }}
run: |
sudo apt update
sudo apt install clang-15 --install-suggests
sudo apt install libc++-15-dev libc++abi-15-dev
# Exit on error
set -e
# Download and execute the LLVM installation script for the specified Clang version
echo "-----> Downloading and executing the LLVM installation script for Clang ${{ matrix.clang_version }}"
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh ${{ matrix.clang_version }}

echo "-----> Installing libc++"
sudo apt-get install -y libc++-${{ matrix.clang_version }}-dev libc++abi-${{ matrix.clang_version }}-dev libunwind-${{ matrix.clang_version }} libunwind-${{ matrix.clang_version }}-dev libc6 libzstd1

# Update the symbolic link to point to the newly installed Clang version
echo "-----> Updating the symbolic link to point to Clang ${{ matrix.clang_version }}"
sudo rm -f /usr/bin/clang++
sudo ln -s /usr/bin/clang++-${{ matrix.clang_version }} /usr/bin/clang++

# Find the system libc++ installations
find /usr -type f \( -name 'std.cppm' -o -name 'std.compat.cppm' \) -exec echo "Found: {}" \;

- name: Generate a Zork++ release build
run: |
Expand All @@ -42,4 +58,4 @@ jobs:
cp ./Zork/zork++/target/release/zork++ .

- name: Running the tests for ${{ matrix.os }} with Zork++
run: ./zork++ --match-files gh_linux -vv -c run
run: ./zork++ --match-files gh_linux -vv -c test
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ data.txt
out/
.idea/
gcm.cache/
CMakeLists.txt
cmake-build-debug
.clangd
compile_commands.json
notes.txt
zork
*.exe
.cache
.clang-format
Empty file added Makefile
Empty file.
16 changes: 16 additions & 0 deletions zero/ifc/commons/concepts.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ import type_traits;

export namespace zero::concepts {

/// \brief Constrain for types that has an operator<< overload
template <typename T>
concept Ostreamable = requires(const T& t, std::ostream& os) {
{ os << t } -> std::same_as<std::ostream&>;
};

/// \brief Constrain for types that has an std::to_string implementation
template <typename T>
concept StringConvertible = requires(const T& t) {
{ std::to_string(t) } -> std::same_as<std::string>;
};

/// \brief Constrain for types with either operator<< or std::to_string
template <typename T>
concept Printable = Ostreamable<T> || StringConvertible<T>;

/**
* @brief checks if the type is a type with a push_back
* member method implemented
Expand Down
26 changes: 12 additions & 14 deletions zero/ifc/commons/typedefs.cppm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @brief Provides a custom way of reexport common types and symbols typically
* found on some system headers in a convenient and encapsulated way.
*
*
* The main motivation of this module interface unit is to wrap all the system
* headers that has standard C++ typedefs, avoding the user to have to include
* on every file that is required those definitions, that also must be defined
Expand All @@ -14,45 +14,43 @@
* Defined in header <cstring>
* Defined in header <ctime>
* Defined in header <cuchar>
*
* Defined in header <cwchar> (since C++17)
*
* Defined in header <cwchar> (since C++17)
* ```
*/

export module typedefs;

#ifdef __clang__
#if defined(__clang__) || defined(_MSC_VER)
import std;
#elif defined(__GNUC__)
import <cstdio>;
#elif defined(_MSC_VER)
import std.core;
#endif

export namespace zero {
/**
* @brief `zero::size_t` is a typedef for wrapping the `std::size_t`, which is the unsigned integer type of the result
* @brief `zero::size_t` is a typedef for wrapping the `std::size_t`, which is the unsigned integer type of the result
* of the sizeof operator as well as the sizeof... operator and the alignof operator.
* The bit width of std::size_t is not less than 16.
* zero::size_t can store the maximum size of a theoretically possible object of any type (including array).
* A type whose size cannot be represented by zero::size_t is ill-formed. On many platforms
* A type whose size cannot be represented by zero::size_t is ill-formed. On many platforms
* (an exception is systems with segmented addressing) zero::size_t can safely store the value of any non-member pointer,
* in which case it is synonymous with std::uintptr_t.
* in which case it is synonymous with std::uintptr_t.
*/
typedef std::size_t size_t;

/**
* @brief zero::ptrdiff_t is a type alias for the std::ptrdiff_t,
* @brief zero::ptrdiff_t is a type alias for the std::ptrdiff_t,
* being the signed integer type of the result of subtracting two pointers.
*
* is used for pointer arithmetic and array indexing, if negative values are
* possible.
*
* is used for pointer arithmetic and array indexing, if negative values are
* possible.
* Programs that use other types, such as int, may fail on, e.g. 64-bit systems
* when the index exceeds INT_MAX or if it relies on 32-bit modular arithmetic
*
*
* Most common place of use if usually working with iterators, specially to fullfil
* the `difference_type` template argument
*/
Expand Down
8 changes: 4 additions & 4 deletions zero/ifc/iterators/internal/iterator_detail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ namespace iterator::__detail {
struct arrow_proxy {
Reference r;

arrow_proxy(Reference&& value) : r(std::move(value)) {}
explicit arrow_proxy(Reference&& value) : r(std::move(value)) {}
Reference* operator->() const { return &r; }
};

/**
* @brief The iterator declares itself a single pass iterator.
* input or output iterators must meet this requirement
* input or output iterators must meet this requirement
*/
template <typename T>
concept is_single_pass = bool(T::single_pass_iterator);
Expand Down Expand Up @@ -62,7 +62,7 @@ namespace iterator::__detail {
template <typename T>
using infer_difference_type_t = typename infer_difference_type<T>::type;

/// Partial template speciallizations to allow us to deduce the
/// Partial template specializations to allow us to deduce the
/// iterator mandatory `value:type`
template <typename T>
requires requires { typename T::value_type; }
Expand Down Expand Up @@ -102,7 +102,7 @@ namespace iterator::__detail {

/// Helper concept to declare a later-deduced parameter type,
/// but that type is still constrained to be a type that we
///don’t yet know
/// don’t yet know
template <typename Arg, typename Iter>
concept difference_type_arg =
std::convertible_to<Arg, infer_difference_type_t<Iter>>;
Expand Down
2 changes: 1 addition & 1 deletion zero/ifc/iterators/iterator.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

export module iterator;

export import :concepts;
export import :concepts; ///< Iterator concepts

export import :input_iterator;
export import :iterator_facade;
Expand Down
16 changes: 8 additions & 8 deletions zero/ifc/iterators/iterator_facade.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import :detail;
import std;

export namespace zero::iterator {
/**
* @brief CRTP base class for provide an iterator facade that quickly
* allows the user to build any kind of iterator
*/
template <typename Derived>
/**
* @brief CRTP base class for provide an iterator facade that quickly
* allows the user to build any kind of iterator
*/
template <typename Derived>
class iterator_facade {
private:
friend Derived;
iterator_facade() {}
iterator_facade() = default;

auto _self() -> Derived& {
return static_cast<Derived&>(*this);
Expand Down Expand Up @@ -147,7 +147,7 @@ template <typename Derived>
* the things on the standard that expects some properties from an iterator,
* we must specialize `std::iterator_traits` for our facade.
*
* Why? For example, when some algorythm will request for
* Why? For example, when some algorithm will request for
* `iterator_implementation::value_type`, the implementor will get errors,
* because there's no `value_type` type member.
*
Expand All @@ -157,7 +157,7 @@ template <typename Derived>
* `self_type::value_type`, and we can't know it until after the full definition
* of `self_type`.
*
* This is a classical know issue with the `CRTP` idiom, the derived types are uncomplete
* This is a classical know issue with the `CRTP` idiom, the derived types are uncompleted
* types until is full definition. Luckily, the standard allows to specialize
* `std::iterator_traits` for user defined types, so the specialization below is a
* partial specialization for any class that is derived from our facade and specialized
Expand Down
19 changes: 9 additions & 10 deletions zero/ifc/iterators/legacy/legacy_output_iterator.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export namespace zero::iterator::legacy
template <typename T>
struct output_iter : base_it<T> {
private:
T *_elem;
T *_ptr;

// TODO move this to the details partition
/**
Expand All @@ -29,7 +29,7 @@ export namespace zero::iterator::legacy
struct output_iter_proxy {
output_iter<Z> &_iter;

constexpr output_iter_proxy(output_iter<Z> &iter) noexcept : _iter(iter) {}
constexpr explicit output_iter_proxy(output_iter<Z> &iter) noexcept : _iter(iter) {}

template <typename U>
constexpr auto operator=(const U &val) -> output_iter_proxy& {
Expand All @@ -49,20 +49,20 @@ export namespace zero::iterator::legacy
};

public:
constexpr output_iter<T>() noexcept = default;
constexpr output_iter(T &elem) noexcept : _elem(&elem) {}
constexpr output_iter<T>() noexcept = default; // Left defaulted and not deleted because the legacy implementation
constexpr explicit output_iter(T& elem) noexcept : _ptr(&elem) {}

constexpr output_iter<T>(const output_iter<T> &other) = default;
constexpr output_iter<T>(output_iter<T> &&other) noexcept = default;

template <typename U>
constexpr auto operator=(const U &val) -> output_iter & {
if constexpr (std::is_base_of_v<std::ostream, std::remove_reference_t<T>>)
*_elem << val;
*_ptr << val;
else if constexpr (zero::concepts::has_push_back<std::remove_reference_t<T>, const U &>)
_elem->push_back(val);
_ptr->push_back(val);
else
*_elem++ = val;
*_ptr++ = val;
return *this;
}

Expand All @@ -88,8 +88,7 @@ export namespace zero::iterator::legacy

[[nodiscard]]
constexpr friend auto operator!=(const output_iter& lhs, const output_iter& rhs) noexcept -> bool {
return not (lhs == rhs);
return lhs != rhs;
}
};

}
}
11 changes: 11 additions & 0 deletions zero/ifc/math/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ This library aims to provide mathematical operations, operators and symbols, for
in standalone mathematical operations or in more complex environments, like solving problems
in diverse science fields.

## Numbers
This module brings certain types for represents and operate with some sets of numbers that exists in maths.
- Natural Numbers (ℕ)
- Integers (ℤ)
- Rationals (ℚ)
- Irrationals ( /* Not yet implemented */ )
- Reals (ℝ)
- ComplexNumbers (ℂ)
- Quaternions (ℍ)
- Primes (ℙ)

## Ops
TODO

Expand Down
36 changes: 36 additions & 0 deletions zero/ifc/math/general.cppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* @brief Contains general types/concepts/operations that are meant to be
* shared across the multiple partitions of the module math
*/

export module math:general;

import std;
import math.symbols;

/// Forward declarations of the 'Numbers types', so they can be shared across different
/// module partitions of 'math'
export namespace zero::math {
class Natural;
class Integer;
class Rational;
class Irrational;
class Real;
class Complex;

/// Concept to act as an interface for the abstract concept of 'number' in mathematics.
/// In particular, this interface represents a kind of number that belongs to a concrete set of numbers,
/// for example, the naturals, the integers, the reals, the complex numbers...
template <typename T>
concept Number = (
std::is_same_v<T, Natural> ||
std::is_same_v<T, Integer> ||
std::is_same_v<T, Rational> ||
std::is_same_v<T, Irrational> ||
std::is_same_v<T, Real> ||
std::is_same_v<T, Complex>
) && requires {
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
};
}
4 changes: 2 additions & 2 deletions zero/ifc/math/linear_algebra/matrix.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ export {
Matrix() = delete;

/// Row Matrix constructor
constexpr Matrix<Rows, Cols, T>(
constexpr Matrix(
std::initializer_list<DataRow> rows
) requires RowMatrix<Orientation> : data {rows} {}
/// Column Matrix constructor
constexpr Matrix<Cols, Rows, T>(
constexpr Matrix(
std::initializer_list<DataCol> columns
) requires ColumnMatrix<Orientation> : data {columns} {}

Expand Down
5 changes: 3 additions & 2 deletions zero/ifc/math/math.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
* This module serves as the public interface for the mathematical
* types and operations defined in the library.
*/

export module math;

export import :general;
export import math.ops;
export import :numbers;
export import math.symbols;
export import math.linear_algebra;
export import math.linear_algebra;
Loading
Loading