<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2459: std::polar should require a non-negative rho</title>
<meta property="og:title" content="Issue 2459: std::polar should require a non-negative rho">
<meta property="og:description" content="C++ library issue. Status: C++17">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2459.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#C++17">C++17</a> status.</em></p>
<h3 id="2459"><a href="lwg-defects.html#2459">2459</a>. <code>std::polar</code> should require a non-negative rho</h3>
<p><b>Section:</b> 29.4.7 <a href="https://wg21.link/complex.value.ops">[complex.value.ops]</a> <b>Status:</b> <a href="lwg-active.html#C++17">C++17</a>
 <b>Submitter:</b> Marshall Clow <b>Opened:</b> 2014-10-22 <b>Last modified:</b> 2017-07-30</p>
<p><b>Priority: </b>0
</p>
<p><b>View all other</b> <a href="lwg-index.html#complex.value.ops">issues</a> in [complex.value.ops].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++17">C++17</a> status.</p>
<p><b>Discussion:</b></p>
<p>
Different implementations give different answers for the following code:
</p>
<blockquote><pre>
#include &lt;iostream&gt;
#include &lt;complex&gt;

int main ()
{
  std::cout &lt;&lt; std::polar(-1.0, -1.0) &lt;&lt; '\n';
  return 0;
}
</pre></blockquote>
<p>
One implementation prints:
</p>
<blockquote><pre>
(nan, nan)
</pre></blockquote>
<p>
Another:
</p>
<blockquote><pre>
(-0.243068, 0.243068)
</pre></blockquote>
<p>
Which is correct? Or neither?
<p/>
In <a href="http://lists.cs.uiuc.edu/pipermail/cfe-dev/2013-November/033591.html">this list</a>, 
Howard Hinnant wrote:
</p>
<blockquote class="note">
<p>
I've read this over several times.  I've consulted C++11, C11, and IEC 10967-3.  [snip]
<p/>
I'm finding:
</p>
<ol>
<li><p>The magnitude of a complex number <code>== abs(c) == hypot(c.real(), c.imag())</code> and is always non-negative 
(by all three of the above standards).</p></li>
<li><p>Therefore no complex number exists for which <code>abs(c) &lt; 0</code>.</p></li>
<li><p>Therefore when the first argument to <code>std::polar</code> (which is called <code>rho</code>) is negative, no complex number 
can be formed which meets the post-conidtion that <code>abs(c) == rho</code>.</p>
</li>
</ol>
<p>
One could argue that this is already covered in 29.4 <a href="https://wg21.link/complex.numbers">[complex.numbers]</a>/3, but I think it's worth making explicit.
</p>
</blockquote>

<p><i>[2015-02, Cologne]</i></p>

<p>
Discussion on whether theta should also be constrained.<br/> 
TK: infinite theta doesn't make sense, whereas infinite rho does (theta is on a compact domain, rho is on a non-compact domain).<br/>
AM: We already have a narrow contract, so I don't mind adding further requirements. Any objections to requiring that theta be finite?<br/>
Some more discussion, but general consensus. Agreement that if someone finds the restrictions problematic, they should write 
a proper paper to address how <code>std::polar</code> should behave. For now, we allow infinite rho (but not NaN and not negative), 
and require finite theta. 
<p/>
No objections to tentatively ready.
</p>


<p id="res-2459"><b>Proposed resolution:</b></p>
<p>This wording is relative to N4296.</p>

<ol>
<li><p>Change 29.4.7 <a href="https://wg21.link/complex.value.ops">[complex.value.ops]</a> around p9 as indicated</p>

<blockquote><pre>
template&lt;class T&gt; complex&lt;T&gt; polar(const T&amp; rho, const T&amp; theta = 0);
</pre>
<blockquote>
<p>
<ins>-?- <i>Requires</i>: <code>rho</code> shall be non-negative and non-NaN. <code>theta</code> shall be finite.</ins>
<p/>
-9- <i>Returns</i>: The complex value corresponding to a complex number whose magnitude is <code>rho</code> and whose
phase angle is <code>theta</code>.
</p>
</blockquote>
</blockquote>
</li>
</ol>





</body>
</html>
