This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of CD1 status.

781. std::complex should add missing C99 functions

Section: 28.4.7 [complex.value.ops] Status: CD1 Submitter: Daniel Krügler Opened: 2008-01-26 Last modified: 2016-01-28

Priority: Not Prioritized

View all other issues in [complex.value.ops].

View all issues with CD1 status.

Discussion:

A comparision of the N2461 header <complex> 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:

  1. 7.3.9.4: (required elements of the C99 library)
    The cproj functions
  2. 7.26.1: (optional elements of the C99 library)
    cerf    cerfc    cexp2
    cexpm1  clog10   clog1p
    clog2   clgamma  ctgamma
    

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

Please note also that the current entry polar in 28.4.9 [cmplx.over] p. 1 should be removed from the mentioned overload list. It does not make sense to require that a function already expecting scalar arguments should cast these arguments into corresponding complex<T> arguments, which are not accepted by this function.

Proposed resolution:

In 28.4.2 [complex.syn] add just between the declaration of conj and fabs:

template<class T> complex<T> conj(const complex<T>&);
template<class T> complex<T> proj(const complex<T>&);
template<class T> complex<T> fabs(const complex<T>&);

In 28.4.7 [complex.value.ops] just after p.6 (return clause of conj) add:

template<class T> complex<T> proj(const complex<T>& x);

Effects: Behaves the same as C99 function cproj, defined in subclause 7.3.9.4."

In 28.4.9 [cmplx.over] p. 1, add one further entry proj to the overload list.

The following function templates shall have additional overloads:

arg           norm 
conj          polar proj
imag          real