-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
<complex> Implement p0415r1 #367
<complex> Implement p0415r1 #367
Conversation
187c57a
to
21ffa54
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an excellent start, thank you! As we previously discussed, we know that _Div
is incomplete. Additionally, I observe that P0415R1 specifies that the "additional overloads" of norm
, conj
, imag
, and real
need to be constexpr
in C++20; that also appears to be unimplemented so far.
6537085
to
339c106
Compare
Maybe I should break it down into a few pr? |
It's a judgement call. We prefer feature PRs to be complete, i.e. not requiring additional PRs to complete the feature. (We make exceptions in rare cases, e.g. charconv, spaceship, and ranges.) We also prefer bugfixes to be complete, but incremental changes can be okay as long as each step is a strict improvement. Separating PRs is useful when changes are large and not intertwined (especially when one of the changes is mechanical or nearly so). It's usually okay to have a large change bundled with a few small improvements "while you're in the neighborhood", though. And sometimes it's just difficult to avoid bundling large, interconnected changes together. One final reason to prefer splitting PRs when possible is that it makes the commit history more comprehensible, even if your reviewers have a high tolerance for larger PRs (as I do, having reviewed truly massive changes over the last decade). In this case, I believe that fixing #325 isn't strongly related to constexprization (and WG21-P0415 doesn't change |
a0f8e9e
to
339c106
Compare
@StephanTLavavej For fix #325 creat new pr #358 For this pr, everything is done, except |
|
* operator+ * operator- * operator* * operator/ (partially) * norm * conj * real * imag * operator= * operator+= * operator-= * operator-= * operator*= * operator/= (partially)
339c106
to
27cbd9b
Compare
|
c600e01
to
3b94871
Compare
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
I've enabled the libcxx tests that are supposed to check this feature. |
The last thing I might ask for is that you add a test to the I'd probably defer to @StephanTLavavej as to whether or not that is necessary though. |
is_constant_evaluated and bit_cast are now always available in C++20 mode. Additionally, we don't need `else` after `if ... return`, which avoids having non-braced control flow.
In C++20 mode, we can always use bit_cast. At runtime, it should be significantly more efficient than calling _Dtest etc. which is separately compiled and performs a full classification instead of testing for just NaN. Avoid unnecessary static_cast<double> - our long double is always 64-bit, and double is already double. Use auto after bit_cast to avoid repeating the type. Add const. For consistency, use named _Uint for 32-bit float too.
Copy bit_cast in <bit> to _Bit_cast in <xutility>, superseding _Bit_cast in <charconv>. Unlike C++20 bit_cast, _Bit_cast is always available. (<xutility> is a common ancestor of <complex> and <charconv>, and includes the necessary machinery for this definition.) I verified that MSVC, Clang, and IntelliSense all accept `__builtin_bit_cast` in 14/17 mode. For CUDA, I provide the memcpy fallback (which isn't constexpr, of course). Finally, _Isinf should use _Bit_cast; I'm marking that with a comment (and will file a GitHub issue in the future) instead of extending this PR indefinitely.
I'm reviewing this now - I've pushed a merge with master, a feature-test macro test update, and |
This extends the PR a bit more than strictly necessary, but I realized it was simpler than filing an issue. Also use `const auto` after static_cast<double>.
This eliminates the _GENERIC_MATHC0X and _GENERIC_MATHC1X macros in favor of directly stamping out the functions. (Over the years, we've moved away from the practice of using macros to stamp out highly repetitive code. The only remaining scenario where I believe that macros are valuable is when we need to stamp out something for every possible calling convention etc. as that's incredibly verbose and platform-dependent.) Additionally, this changes _Promote_to_float to _Upgrade_to_double. This is better-named in two different ways ("promote" is a Word Of Power that isn't exactly applicable here, and the replacement type is double). It's also less verbose and higher throughput (the former is obvious; the latter is because struct templates are more expensive for compilers to instantiate, as they have to do a lot of work when they generate a class definition). Avoiding macros allows us to perform a couple of micro-cleanups: we can directly return 0 (no need to static_cast to floating type) and we don't have to parenthesize `_Left * _Left` to make clang-format happy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy with what I see here, but a little concerned about test coverage. The names of the libc++ tests suggest they only cover real
and imag
- should we have some basic smoke tests to ensure these functions are callable in a constant expression with at least one set of parameter values?
I am writing test coverage at this very moment. |
Thanks for implementing this feature - we're one step closer to C++20 completeness! 😸🎉 (Along this way, this uncovered a bug in the compiler's support for modules, which our FE dev Cameron DaCamara has already fixed!) |
Description
This is an in progress implementation of constexpr
<complex>
.Will resolve issue #16, #190.
Checklist
Be sure you've read README.md and understand the scope of this repo.
If you're unsure about a box, leave it unchecked. A maintainer will help you.
_Ugly
as perhttps://eel.is/c++draft/lex.name#3.1 or there are no product code changes.
verified by an STL maintainer before automated testing is enabled on GitHub,
leave this unchecked for initial submission).
members, adding virtual functions, changing whether a type is an aggregate
or trivially copyable, etc.).
the C++ Working Draft (including any cited standards), other WG21 papers
(excluding reference implementations outside of proposed standard wording),
and LWG issues as reference material. If they were derived from a project
that's already listed in NOTICE.txt, that's fine, but please mention it.
If they were derived from any other project (including Boost and libc++,
which are not yet listed in NOTICE.txt), you must mention it here,
so we can determine whether the license is compatible and what else needs
to be done.