<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 781: std::complex should add missing C99 functions</title>
<meta property="og:title" content="Issue 781: std::complex should add missing C99 functions">
<meta property="og:description" content="C++ library issue. Status: CD1">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue781.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#CD1">CD1</a> status.</em></p>
<h3 id="781"><a href="lwg-defects.html#781">781</a>. <code>std::complex</code> should add missing C99 functions</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#CD1">CD1</a>
 <b>Submitter:</b> Daniel Kr&uuml;gler <b>Opened:</b> 2008-01-26 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</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#CD1">CD1</a> status.</p>
<p><b>Discussion:</b></p>
<p>
A comparision of the N2461 header <code>&lt;complex&gt;</code> synopsis ([complex.syn])
with the C99 standard (ISO 9899, 2nd edition and the two corrigenda) show
some complex functions that are missing in C++. These are:
</p>

<ol>
<li>
7.3.9.4: (required elements of the C99 library)<br/>
The <code>cproj</code> functions
</li>
<li>
7.26.1: (optional elements of the C99 library)<br/>
<pre>
cerf    cerfc    cexp2
cexpm1  clog10   clog1p
clog2   clgamma  ctgamma
</pre>
</li>
</ol>

<p>
I propose that at least the required <code>cproj</code> overloads are provided as equivalent
C++ functions. This addition is easy to do in one sentence (delegation to C99
function).
</p>

<p>
Please note also that the current entry <code>polar</code>
in 29.4.10 <a href="https://wg21.link/cmplx.over">[cmplx.over]</a> p. 1
should be removed from the mentioned overload list. It does not make sense to require that a
function already expecting <em>scalar</em> arguments
should cast these arguments into corresponding
<code>complex&lt;T&gt;</code> arguments, which are not accepted by
this function.
</p>


<p id="res-781"><b>Proposed resolution:</b></p>
<p>
In 29.4.2 <a href="https://wg21.link/complex.syn">[complex.syn]</a> add just between the declaration of <code>conj</code> and <code>fabs</code>:
</p>

<blockquote><pre>
template&lt;class T&gt; complex&lt;T&gt; conj(const complex&lt;T&gt;&amp;);
<ins>template&lt;class T&gt; complex&lt;T&gt; proj(const complex&lt;T&gt;&amp;);</ins>
template&lt;class T&gt; complex&lt;T&gt; fabs(const complex&lt;T&gt;&amp;);
</pre></blockquote>

<p>
In 29.4.7 <a href="https://wg21.link/complex.value.ops">[complex.value.ops]</a> just after p.6 (return clause of <code>conj</code>) add:
</p>

<blockquote>
<pre>
template&lt;class T&gt; complex&lt;T&gt; proj(const complex&lt;T&gt;&amp; x);
</pre>
<blockquote><p>
<i>Effects:</i> Behaves the same as C99 function <code>cproj</code>, defined in
subclause 7.3.9.4."
</p></blockquote>
</blockquote>

<p>
In 29.4.10 <a href="https://wg21.link/cmplx.over">[cmplx.over]</a> p. 1, add one further entry <code>proj</code> to
the overload list.
</p>

<blockquote>
<p>
The following function templates shall have additional overloads:
</p>
<blockquote><pre>
arg           norm 
conj          <del>polar</del> <ins>proj</ins>
imag          real
</pre></blockquote>
</blockquote>






</body>
</html>
