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

LCM of 2 up to N integer numbers #20

Merged
merged 40 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
e55bfe1
physics-library - Added a template parameter to the base dimension ba…
Mar 27, 2023
b489476
physics-lib - Now dimensions handles in a nicer way the relation with…
TheRustifyer Mar 29, 2023
daf31d1
physics-lib - WIP - Trying to really understand how to use certain tr…
TheRustifyer Mar 29, 2023
b08e3fc
physics-lib - derived_units type is now able to offer a member with t…
TheRustifyer Mar 30, 2023
3e07ead
physics-lib - Refining the derived dimension concept
TheRustifyer Mar 30, 2023
f310529
physics-lib - Now we can calculate the dimensionality (dimension expo…
TheRustifyer Mar 31, 2023
c38cdb3
physics-lib - First success of implementing an arithmetic operation (…
TheRustifyer Mar 31, 2023
00275ed
physics-library - Renaming ratio prefixes
Mar 31, 2023
f4ad4f7
physics-library - Concept SameDimensionality to constrain derived mag…
TheRustifyer Mar 31, 2023
e289b81
physics-library - Getting rid out of the idea of tagging a concrete d…
TheRustifyer Apr 1, 2023
c8cd307
str-manip - Upgrading the split_str algorithm
TheRustifyer Apr 1, 2023
fc2a8c9
physics-library - Cleaning the implementation of the derived magnitud…
Apr 1, 2023
70d0b7d
physics-library - Unit tests for the derived magnitudes
Apr 1, 2023
2695684
Merge branch 'zerodaycode:main' into physics-library
TheRustifyer Apr 1, 2023
87c8345
Merge branch 'physics-library'
Apr 1, 2023
d91c68c
Upgrading the README.md file to share our new ideas and vision and to…
Apr 1, 2023
a1a8d62
Jason Turner recommendations- Enabling warnings as errors, and all po…
TheRustifyer Apr 2, 2023
a9a3f7e
quantities-library - The quantities deserves it's own place as a sub-…
TheRustifyer Apr 2, 2023
a2a2ec8
Documentation - Added documentation and links for every library/subli…
TheRustifyer Apr 2, 2023
73f6112
physics-lib - Implementing a simple member function that acts as a co…
TheRustifyer Apr 3, 2023
0237119
physics-lib - Quantities now are printed with their units when the os…
TheRustifyer Apr 3, 2023
a527c90
physics-lib - Preparing the PR to upstream. Project CLang's configura…
TheRustifyer Apr 4, 2023
f118cc5
physics-lib - Including all the base dimensions, some units related w…
TheRustifyer Apr 4, 2023
399ad1e
physics-lib - Reworking a little bit our definition for the ratio type
TheRustifyer Apr 4, 2023
ed499e5
physics-lib - Strange WIP about days to hours
TheRustifyer Apr 4, 2023
4050401
physics-lib - Added days as a quantity available as a dimension of time
TheRustifyer Apr 5, 2023
c3308ee
Merge branch 'zerodaycode:main' into main
TheRustifyer Apr 5, 2023
7494e41
github-actions - Adding the tests for the project
TheRustifyer Apr 5, 2023
fe7d58e
Merge branch 'zerodaycode:main' into main
TheRustifyer Apr 5, 2023
20fe5ee
Solving errors about boolean atomic constraints in concepts, detected…
TheRustifyer Apr 26, 2023
ac7b94c
Merge branch 'main' of https://github.com/zerodaycode/Zero
TheRustifyer Apr 26, 2023
afc9485
Merge branch 'main' of https://github.com/zerodaycode/Zero
May 1, 2023
05d5ab5
Merge branch 'main' of https://github.com/zerodaycode/Zero
TheRustifyer May 4, 2023
4d6c078
Merge branch 'main' of https://github.com/Pyzyryab/Zero
TheRustifyer May 4, 2023
7fd6e64
Reordering the main file with the live examples. Quantities examples …
TheRustifyer May 4, 2023
73ee5c1
Creating a variadic template that is able to provide the GCD of N num…
TheRustifyer May 4, 2023
eadbe6b
Merge branch 'main' of https://github.com/zerodaycode/Zero
TheRustifyer May 4, 2023
654559b
Removed the consteval version of GCD, since constexpr will take care …
TheRustifyer May 4, 2023
a8f0dfb
Reorganizing the algebraic ops into their own inner namespace, and br…
TheRustifyer May 4, 2023
b12d4f8
Added new functions, this time to calculate the LCM of 2, up to N int…
TheRustifyer May 4, 2023
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
Prev Previous commit
Next Next commit
physics-lib - Preparing the PR to upstream. Project CLang's configura…
…tion is upgraded to the 2b flag for the C++ standard. Internal partition for the details is a raw module
  • Loading branch information
TheRustifyer committed Apr 4, 2023
commit a527c909c1fdb2ef09f94ac14a99637026413031
2 changes: 1 addition & 1 deletion zero/ifc/physics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ for define the symbol of kilogram, according to the `SI`
## Conversion

We provide in the API an easy way to convert quantities of the same dimension (for the bases) or with the
same dimensionality (for derived) with a simple template member function called `to<Magnitude Target>`.
same dimensionality (for derived) with a simple template member function called `.to<Magnitude>()`.
Here's an example:

```
Expand Down
66 changes: 66 additions & 0 deletions zero/ifc/physics/quantities/internal/quantities_detail.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* @brief Partition for holding the implementation
* details that won't contribute to the external API of the
* units module.
*
* Due to the recursive function template for
* formatting the `derived magnitude symbols`, we can't use
* this as an internal partition, due to the linker is not able
* to resolve the template in order to link it at call site
*/

export module physics.quantities:quantities.detail;

import std;

import type_info;
import str_manip;

export namespace quantities::__detail {
template<typename T>
struct dimensions_exponents;

template<typename... BaseDimensions>
struct dimensions_exponents<std::tuple<BaseDimensions...>> {
static constexpr auto value = std::array<short, sizeof...(BaseDimensions)> {BaseDimensions::base_dimension::dimension::dimension_exp...};
};

template<typename T>
struct ratios_detail;

template<typename... BaseUnits>
struct ratios_detail<std::tuple<BaseUnits...>> {
using ratios = std::tuple<typename BaseUnits::ratio...>;
};

template <typename T>
struct ratios_product_calculator;

template<typename... BaseUnitsRatios>
struct ratios_product_calculator<std::tuple<BaseUnitsRatios...>> {
static constexpr auto value = (1 * ... * BaseUnitsRatios::value);
};

template<typename M, int N = 1>
void derived_magnitude_symbols(std::string& out) {
if constexpr (N == 1)
out += " ";

using type = typename std::tuple_element<N - 1, typename M::units>::type;
const auto total_elements = std::tuple_size<typename M::units>::value;
const int dim_exp = std::tuple_element<N - 1, typename M::derived_dimension::dimensions>::type::dimension_exp;

auto splitted = zero::split_str(zero::types::type_name<type>(), "::").back();
auto s_symbol = splitted.substr(0, splitted.length() - 1);

out += s_symbol;

if constexpr (dim_exp != 1)
out += std::to_string(dim_exp);
if constexpr (total_elements > N)
out += "*";

if constexpr (N - 1 < total_elements - 1)
derived_magnitude_symbols<M, N + 1>(out);
}
}
35 changes: 0 additions & 35 deletions zero/ifc/physics/quantities/internal/units_detail.cpp

This file was deleted.

31 changes: 4 additions & 27 deletions zero/ifc/physics/quantities/quantity.cppm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @brief Module for design types and behavior associated with Physical Quantities.
*
*
* A physical quantity can be understand as a real world magnitude, related with
* their units in the international system
*/
Expand All @@ -15,7 +15,8 @@ import :ratios;
import :dimensions;
import :units;
import :units.symbols;
import :units.detail;
import :quantities.detail;


export namespace zero::physics {
template <typename T>
Expand Down Expand Up @@ -275,30 +276,7 @@ export namespace zero::physics {
return quantity<DM2, T2>((lhs.amount * dm1_dimensionality) / (rhs.amount * dm2_dimensionality));
}

// TODO this template recursive function isn't linking from the details
// partition module, so it must be in the public API until we found a better solution
template<typename M, int N = 1>
void derived_magnitude_symbols(std::string& out) {
if constexpr (N == 1)
out += " ";

using type = typename std::tuple_element<N - 1, typename M::units>::type;
const auto total_elements = std::tuple_size<typename M::units>::value;
const int dim_exp = std::tuple_element<N - 1, typename M::derived_dimension::dimensions>::type::dimension_exp;

auto splitted = zero::split_str(zero::types::type_name<type>(), "::").back();
auto s_symbol = splitted.substr(0, splitted.length() - 1);

out += s_symbol;

if constexpr (dim_exp != 1)
out += std::to_string(dim_exp);
if constexpr (total_elements > N)
out += std::string{"*"};

if constexpr (N - 1 < total_elements - 1)
derived_magnitude_symbols<M, N + 1>(out);
}

/**
* Sends to an output stream a formatted version of some {@link quantity}
Expand All @@ -309,11 +287,10 @@ export namespace zero::physics {
os << q.amount << " " << zero::split_str(zero::types::type_name<typename M::symbol>(), "::").back();
else {
std::string out;
derived_magnitude_symbols<M>(out);
::derived_magnitude_symbols<M>(out);
os << q.amount << out;
}

return os;
}
}

2 changes: 1 addition & 1 deletion zero/ifc/physics/quantities/units.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import concepts;
import :ratios;
import :dimensions;
import :units.symbols;
import :units.detail;
import :quantities.detail;

using namespace quantities::__detail;

Expand Down
2 changes: 1 addition & 1 deletion zork.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ interfaces = [

# The physics library
# The quantities library
{ file = 'physics/quantities/internal/units_detail.cpp', partition = { module = 'physics.quantities', partition_name = 'units.detail' } },
{ file = 'physics/quantities/internal/quantities_detail.cpp', partition = { module = 'physics.quantities', partition_name = 'quantities.detail' } },

{ file = 'physics/quantities/ratios.cppm', partition = { module = 'physics.quantities' } },
{ file = 'physics/quantities/units.symbols.cppm', module_name = 'units.symbols', partition = { module = 'physics.quantities' } },
Expand Down