Talk:cpp/numeric/math/abs
From cppreference.com
< Talk:cpp | numeric/math
Suggest we replace "argument of arithmetic type X
such that X(0) < X(-1) is true
and X
" with "unsigned argument". Don't think there's risk of misinterpretation doing so. --Ybab321 (talk) 03:42, 6 November 2020 (PST)
- Or maybe use both:
... argument of arithmetic typeX
such that X(0) < X(-1) istrue
(which means on most platforms thatX
is ofunsigned
type) ...
- or something similar. Space Mission (talk) 08:55, 6 November 2020 (PST)
- std::abs can be called with an unsigned char arguments on most platforms, as unsigned char can be promoted to int. How about "an argument of integer type
X
such that the type of +X() is an unsigned integer type"? --Fruderica (talk) 00:23, 7 November 2020 (PST)- I'm happy with the "cannot be converted to int by integral promotion" wording; I think banking on people knowing about unary + doing promotion is a little too cryptic. Full wording change would be like:
- "If
std::abs
is called with an unsigned argument and that cannot be converted to int by integral promotion, the program is ill-formed."
- "If
- Or taking Space Mission's take into account, my proposed wording would be:
- "If
std::abs
is called with an unsigned argument (that is, of arithmetic typeX
such that X(0) < X(-1) istrue
) that cannot be converted to int by integral promotion, the program is ill-formed."
- "If
- I really just don't like the idea that
std::abs
would warrant any kind of complexity/verbosity/crypticism in its description. --Ybab321 (talk) 04:24, 8 November 2020 (PST)
- I'm happy with the "cannot be converted to int by integral promotion" wording; I think banking on people knowing about unary + doing promotion is a little too cryptic. Full wording change would be like:
- std::abs can be called with an unsigned char arguments on most platforms, as unsigned char can be promoted to int. How about "an argument of integer type