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

feat: unit constants #184

Merged
merged 1 commit into from
Dec 28, 2020
Merged

feat: unit constants #184

merged 1 commit into from
Dec 28, 2020

Conversation

JohelEGP
Copy link
Collaborator

@JohelEGP JohelEGP commented Dec 25, 2020

Resolves #160.
Resolves #48.

The tests handles all comments raised in #48.

@JohelEGP

This comment has been minimized.

@JohelEGP JohelEGP force-pushed the unit_constants branch 7 times, most recently from bc67845 to 95e1c52 Compare December 26, 2020 01:48
@JohelEGP
Copy link
Collaborator Author

JohelEGP commented Dec 26, 2020

namespace unit_constants isn't inline to avoid shadowing warnings and errors.

@JohelEGP JohelEGP force-pushed the unit_constants branch 4 times, most recently from 0f646bb to 8133fba Compare December 26, 2020 02:43
@JohelEGP

This comment has been minimized.

@JohelEGP

This comment has been minimized.

@JohelEGP

This comment has been minimized.

Copy link
Owner

@mpusz mpusz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like this approach. Thanks!

However, in order to be able to merge it, CI issues have to be resolved first.

src/include/units/physical/si/us/base/length.h Outdated Show resolved Hide resolved
src/include/units/bits/one_rep.h Outdated Show resolved Hide resolved
test/unit_test/static/unit_constants.cpp Outdated Show resolved Hide resolved
test/unit_test/static/unit_constants.cpp Show resolved Hide resolved
test/unit_test/static/unit_constants.cpp Show resolved Hide resolved
@JohelEGP
Copy link
Collaborator Author

JohelEGP commented Dec 26, 2020

I really like this approach. Thanks!

However, in order to be able to merge it, CI issues have to be resolved first.

Thank you. <snip> It seems done.

@JohelEGP

This comment has been minimized.

@JohelEGP

This comment has been minimized.

@JohelEGP JohelEGP force-pushed the unit_constants branch 3 times, most recently from 435b3fe to ef0c616 Compare December 26, 2020 23:24
@JohelEGP

This comment has been minimized.

@JohelEGP
Copy link
Collaborator Author

JohelEGP commented Dec 27, 2020

Here's the time taken by the main step of the CI.

Compiler + mode ef0c616 f052b1a fa928a5 791d1ef 89359ca 2a522e3 master cabd8b0 master 0fb821a
MSVC Release 6m 3s 5m 40s 7m 59s 6m 33s 6m 36s 6m 35s 5m 54s
MSVC Debug 5m 55s 5m 3s 4m 41s 5m 29s
GCC 10.1 Release 4m 34s 4m 0s 4m 21s 4m 14s 4m 7s 4m 34s 3m 24s 3m 15s
GCC 10.1 Debug 4m 7s 4m 13s 3m 39s 3m 33s 3m 10s 3m 27s 2m 51s 3m 43s
GCC 10.2 Release 4m 14s 3m 52s 4m 19s 3m 31s 3m 54s 3m 23s 4m 5s 3m 6s
GCC 10.2 Debug 4m 19s 4m 18s 4m 0s 3m 27s 3m 17s 2m 58s 3m 19s 2m 39s

Copy link
Owner

@mpusz mpusz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for all those massive changes. A lot of good work!

I have two general comments:

  1. When we leave some code commented out it would be good to provide a comment on why it is commented out.
  2. Please use TODO comments if we should return to some lines of code in the future

and one question:

  1. Do you think that we need *_per_* constants? It is good to have them for now to experiment, but I think that it might be better to just use * / * syntax which probably is easier to understand? It also allows fewer values to maintain and potentially standardize in the future. What is your experience here?

return lhs;
}
template<QuantityValue Rep>
[[nodiscard]] friend constexpr Rep operator*(one_rep, const Rep& rhs) // pending #185
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add TODO in a comment so it will be easier to find and resolve.
BTW, I really recommend Todo Tree VS Code extension.

template<QuantityValue Rep>
[[nodiscard]] constexpr operator Rep() const noexcept
{
return quantity_values<Rep>::one();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:-)

src/include/units/physical/si/typographic/base/length.h Outdated Show resolved Hide resolved
src/include/units/physical/si/fps/base/length.h Outdated Show resolved Hide resolved
src/include/units/physical/si/fps/derived/speed.h Outdated Show resolved Hide resolved
src/include/units/physical/si/iau/base/length.h Outdated Show resolved Hide resolved
src/include/units/physical/si/international/base/length.h Outdated Show resolved Hide resolved
src/include/units/physical/si/international/base/length.h Outdated Show resolved Hide resolved
src/include/units/physical/si/us/base/length.h Outdated Show resolved Hide resolved
test/unit_test/static/unit_constants.cpp Outdated Show resolved Hide resolved
@mpusz
Copy link
Owner

mpusz commented Dec 27, 2020

MSVC Debug seems hung up.

This seems to happen when an assert() is hit for VS Debug. Unfortunately, the assert message is not provided :-(

@mpusz
Copy link
Owner

mpusz commented Dec 27, 2020

Here's the time taken by the main step of the CI.

I do not think we should be concerned about it. This library is designed with C++20 modules in mind. Everything we will predefine in the library will be compiled once and will speed up the compilation of the users' code later on.

Also, now when I fixed VS compilation again and provided a CI for it, I plan to play a bit with vcperf to analyze and possibly improve the build times. Another round of compile-time optimization will come when clang will finally catch up...


static_assert(2 * m == 2_q_m);
static_assert(2 * s == 2_q_s);
#if !defined(_MSC_VER)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please use COMP_MSVC?

BTW, if you feel we can do better here, we can think about an alternative/better way to refer to compilers in a unified way...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For starters, all kind of global identifiers should be "namespaced". In this case, they should be prefixed with UNITS_ or MP_UNITS_ (just like the CMake options).

@JohelEGP
Copy link
Collaborator Author

JohelEGP commented Dec 27, 2020

<snip>

3. Do you think that we need `*_per_*` constants? It is good to have them for now to experiment, but I think that it might be better to just use `* / *` syntax which probably is easier to understand? It also allows fewer values to maintain and potentially standardize in the future. What is your experience here?

They should definitely go away. The purpose is to have natural syntax. 1 * m / s is so much better than 1 * m_per_s. I'm personally drawing the line at _per_. I welcome exceptions like mph, but I'm not so sure about units like Nm (https://en.wikipedia.org/wiki/Newton-metre), which Wikipedia shows as having "symbol N⋅m[1] or N m[1]". Considering that W_per_m_K will go away and there's no mK or m_K, so that one would have to write W / (m * K), should we keep unit constants like Nm?

@JohelEGP JohelEGP force-pushed the unit_constants branch 2 times, most recently from 791d1ef to 89359ca Compare December 27, 2020 19:36
Copy link
Owner

@mpusz mpusz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!!!

@mpusz mpusz merged commit 8dede0d into mpusz:master Dec 28, 2020
@JohelEGP JohelEGP deleted the unit_constants branch December 28, 2020 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: unit constants Poll: UDLs vs constants
2 participants