-
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
<cmath>: signbit() misses overloads for integer types #519
Comments
In addition to DevCom-923187, this was previously reported as Microsoft-internal VSO-521345, VSO-153341, VSO-194989, VSO-294538, and VSO-531712. We resolved those bugs, saying that when LWG-1327 was resolved, the intent was to support floating-point types only. There's a comment in Line 674 in fffbd8f
However, this issue keeps being encountered by users, and I do not see clear language in the current WP justifying our implementation. WG21-N4849 [cmath.syn]/2 simply says "For each set of overloaded functions within I believe that either this is a bug in our implementation, or it's a defect in the Standard that needs an LWG issue to be filed (specifically mentioning the "classification/comparison functions" alongside |
I've asked on the LEWG mailing list a few times about this (choosing to resolve in favor of providing the overloads or not is an LEWG rather than LWG question) but haven't gotten any response. I wanted to write a paper about it but wanted to wait until the "mandating the standard library" papers got merged. |
It looks like WG21-P0175 may have broken the reasoning we use for LWG-1327 -- the old wording said that the "sufficient additional overloads only apply to functions from the C standard library" and in the C standard library they are macros. Now we explicitly declare them as functions... |
LWG-1327 is resolved by Motion 27 at Rapperswil 2010. That applied the wording for US136 from WG21-N3102. The description preceding the wording says
This was also presented to WG14 at the same time; WG14-N1459 makes clear that the C comparison macros are intended to support heterogeneous floating-point types. That's only realizable in the C++ wording if "sufficient additional overloads" apply. |
We should actually tag this as |
Closed #908 as a duplicate of this bug; it received 6 thumbs-up in addition to the submitter. |
@BillyONeal The usefulness of |
That is actually want scares me: it encourages code that looks correct but falls over if the user passes more than 53 bits; I would kinda like to see the user explicitly |
Are you thinking about the functions that'll return a
|
I mean all code that might accidentally mix these things. If the user called something in the fpclassify family that suggests that they are expecting the inputs to behave like floats. Consider the straw man:
works great until T is long long and the input doesn't fit in 53 bits. Maybe stopping that with this isn't a huge win, but I think the amount of code that becomes truly generic across floats and integrals but for these functions is small. But I also am probably not the target user here; that's why I wanted the committee to provide clarification here. |
Great! Have you or somebody else written a proposal? I'd like to see where this goes .... |
Examples where the loss of precision when converted to
|
Just got pinged internally about this one again today :(. |
Is there ever going to be movement on this? As it is, calling What the language WG says aside, this is one of a handful of ongoing issues where MSVC stands apart from pretty much every other major compiler in terms of being able to compile a large project like MAME. Is ideology more important than a working compiler? |
@MooglyGuy the reason we didn't just "fix" this is it is not clear that that is a "fix" or "working". Passing integers to the fpclassify family looks like a bug. I wanted confirmation from the people who actually own the answer as to whether that is intended to work, or intended to be diagnosed as the semantic error that it is. Permanent in source workarounds are easy: cast to double first or guard it for is_floating_point. But I am no longer a maintainer, perhaps a current one has a different read on the situation. |
WG21-P1467 significantly rewrote all of the wording in [cmath.syn]. It is now clear and unambiguous that the floating-point classification functions, including |
My main concern here doesn't even involve floating-point types, That's the origin of my frustration: I can completely understand a level of faff involving the function's implementation for floating-point types due to the fact that IEEE 754 was never a particularly well-defined spec to begin with. But I would expect the function's implementation for integers to be a non-issue as a result, not for the compiler to be popping ambiguity errors. |
I think this issue could be partially fixed by inserting the follow code snippet into // #if _STL_COMPILER_PREPROCESSOR
#include <xtr1common>
template <class _Ty, _STD enable_if_t<_STD is_integral_v<_Ty>, int> = 0>
_NODISCARD _Check_return_ _CONSTEXPR23 int fpclassify(_In_ const _Ty _Ix) noexcept /* strengthened */ {
return _Ix ? -2 : 0; // FP_NORMAL and FP_ZERO in UCRT respectively
}
template <class _Ty, _STD enable_if_t<_STD is_integral_v<_Ty>, int> = 0>
_NODISCARD _Check_return_ _CONSTEXPR23 bool signbit(_In_ const _Ty _Ix) noexcept /* strengthened */ {
if constexpr (static_cast<_Ty>(-1) < _Ty{}) {
return _Ix < 0;
} else {
return false;
}
}
// #include <math.h> After such change, if one includes However, if one just includes |
Thanks for the update! Consider my objection to going here withdrawn.
Again, the issue was never "is this complicated to implement", it was "this function's effects, by virtue of being part of the |
It should indeed compile, but you're probably more correct that the affected code should just be using |
I'm going to resolve this as fixed by #4537, since this now works with |
Dropping "major" to avoid line breaking.
https://developercommunity.visualstudio.com/content/problem/923187/stdsignbit-misses-overloads-for-integer-types.html#reply-923210
jbeder/yaml-cpp#823
The text was updated successfully, but these errors were encountered: