-
Notifications
You must be signed in to change notification settings - Fork 92
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
Test that default constructed objects are zero #529
Conversation
2a6f7d6
to
6e94bcc
Compare
I think these should go before
And test that (0 * m).numerical_value_in(m) == quantity<m, int>::zero() .The earlier tests already check that zero returns 0 or 0.0 .
|
I was under the impression that mp-units/test/unit_test/static/quantity_test.cpp Lines 58 to 63 in 7a270a6
implied that. But thinking about it some more, I'm not too convinced that they guarantee it. |
6e94bcc
to
7ee68df
Compare
I of course have no objection to doing this, but then I'd have to bring in the |
|
In a generic context, we often need to compare arithmetic types to zero. However, mp-units types cannot be default constructed from (say) `double`, so we cann write (e.g.) ```cpp if (x < T(0)) { // ... } ``` Instead, we have to use ```cpp constexpr auto ZERO = T{}; if (x < ZERO) { // ... } ``` This begs the question: Do we have a guarantee that `ZERO==0.0`? Add a unit test that verifies this behavior.
7ee68df
to
274d9e1
Compare
It appears that it is unclear what this PR accomplishes-if anything. I think this can safely be closed. If anyone finds compelling value in it I'll reopen. |
You actually do not mean a default initialization but value/zero-initalization (https://en.cppreference.com/w/cpp/language/zero_initialization) here. In generic code, you can always write: if (x < T{}) {
// ...
} A more detailed discussion on this subject can be found at https://wg21.link/p2982R1#comparison-against-zero. We will discuss this in the Committee and check if there is a guidance in any direction. |
In a generic context, we often need to compare arithmetic types to zero. However, mp-units types cannot be default constructed from (say)
double
, so we cann write (e.g.)Instead, we have to use
This begs the question: Do we have a guarantee that
ZERO==0.0
? Add a unit test that verifies this behavior.