Created on 2014-10-22.00:00:00 last changed 90 months ago
Proposed resolution:
This wording is relative to N4296.
Change [complex.value.ops] around p9 as indicated
template<class T> complex<T> polar(const T& rho, const T& theta = 0);-?- Requires: rho shall be non-negative and non-NaN. theta shall be finite.
-9- Returns: The complex value corresponding to a complex number whose magnitude is rho and whose phase angle is theta.
[ 2015-02, Cologne ]
Discussion on whether theta should also be constrained.
TK: infinite theta doesn't make sense, whereas infinite rho does (theta is on a compact domain, rho is on a non-compact domain).
AM: We already have a narrow contract, so I don't mind adding further requirements. Any objections to requiring that theta be finite?
Some more discussion, but general consensus. Agreement that if someone finds the restrictions problematic, they should write
a proper paper to address how std::polar should behave. For now, we allow infinite rho (but not NaN and not negative),
and require finite theta.
Different implementations give different answers for the following code:
#include <iostream> #include <complex> int main () { std::cout << std::polar(-1.0, -1.0) << '\n'; return 0; }
One implementation prints:
(nan, nan)
Another:
(-0.243068, 0.243068)
Which is correct? Or neither?
In this list, Howard Hinnant wrote:I've read this over several times. I've consulted C++11, C11, and IEC 10967-3. [snip]
I'm finding:
The magnitude of a complex number == abs(c) == hypot(c.real(), c.imag()) and is always non-negative (by all three of the above standards).
Therefore no complex number exists for which abs(c) < 0.
Therefore when the first argument to std::polar (which is called rho) is negative, no complex number can be formed which meets the post-conidtion that abs(c) == rho.
One could argue that this is already covered in [complex.numbers]/3, but I think it's worth making explicit.
History | |||
---|---|---|---|
Date | User | Action | Args |
2017-07-30 20:15:43 | admin | set | status: wp -> c++17 |
2015-05-22 18:31:21 | admin | set | status: ready -> wp |
2015-03-22 19:05:09 | admin | set | messages: + msg7246 |
2015-03-22 19:05:09 | admin | set | status: new -> ready |
2014-11-25 18:50:34 | admin | set | messages: + msg7210 |
2014-10-22 00:00:00 | admin | create |