Boost logo

Boost :

Subject: Re: [boost] Review request: extended complex number library
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2012-03-07 17:36:13

On 03/07/2012 11:20 PM, Christopher Jefferson wrote:
> On 7 Mar 2012, at 22:12, Mathias Gaunard wrote:
>> On 03/06/2012 07:49 PM, Vicente J. Botet Escriba wrote:
>>> you are right. The goal been to provide a faster library implies that
>>> the Boost library should use the standard library when the standard is
>>> more efficient, and we could expect that the standard is faster for the
>>> scope it covers.
>> What about correctness?
>> Most implementations of standard library functions on complex numbers are not correct from a numerical point of view.
> Really? Can you give some examples? Have you reported these issues to the various compiler designers?

Verbatim from the libstdc++ headers

   // 26.2.5/13
   // XXX: This is a grammar school implementation.
   template<typename _Tp>
     template<typename _Up>
     complex<_Tp>::operator*=(const complex<_Up>& __z)
       const _Tp __r = _M_real * __z.real() - _M_imag * __z.imag();
       _M_imag = _M_real * __z.imag() + _M_imag * __z.real();
       _M_real = __r;
       return *this;

This is incorrect for infinite types and causes undue overflow or underflow.

See the C99 or C11 standards, annex G.
It also comes with a possible implementation.

C++ has no equivalent to this annex AFAIK.

Boost list run by bdawes at, gregod at, cpdaniel at, john at