Topic: Complex Numbers


Author: jbuck@Synopsys.COM (Joe Buck)
Date: 1996/07/24
Raw View
I wrote:
>JB> complex is a template; one can have complex<float> and
>JB> complex<double>, but also of any other type that has the
>JB> arithmetic operations defined.
>[...]

vandevod@cs.rpi.edu (David Vandevoorde) writes:
>This has been clarified in Stockholm; the following text was added
>to the draft:
>
>   The effect of instantiating the template `complex' for any type
>   other than float, double or long double is unspecified.

What is the justification for this?  It takes away some of the benefits
of specifying complex as a template, as it means that programmers
who define their own numeric types (rationals, longer-precision reals)
cannot assume that the complex template will work, even though there
was no reason up to now to assume that it should not.

I can understand that a compiler writer might want the freedom to
treat complex<float>, complex<double>, and complex<long double> as
special, but does that require the freedom to completely break
complex<Rational> and complex<int>?
--
-- Joe Buck  <jbuck@synopsys.com> (not speaking for Synopsys, Inc)

Work for something because it is good,
not just because it stands a chance to succeed.    -- Vaclav Havel
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: Matt Austern <austern@sgi.com>
Date: 1996/07/24
Raw View
jbuck@Synopsys.COM (Joe Buck) writes:

> What is the justification for this?  It takes away some of the benefits
> of specifying complex as a template, as it means that programmers
> who define their own numeric types (rationals, longer-precision reals)
> cannot assume that the complex template will work, even though there
> was no reason up to now to assume that it should not.
>
> I can understand that a compiler writer might want the freedom to
> treat complex<float>, complex<double>, and complex<long double> as
> special, but does that require the freedom to completely break
> complex<Rational> and complex<int>?

There was, in fact, some reason to wonder whether or not complex<int>
would work: the standard never specified what the requirements were
for the type with which complex was instantiated.  At the Stockholm
meeting, we discussed the question of what those requirements ought to
be.  It turned out that this was not simply a theoretical problem:
different library implementors really were assuming different
requirements.

We discussed the possibility of coming up with and standardizing a
detailed set of requirements; the intuitive notion is that it should
work for any scalar type that supports the ordinary arithmetic
operations.  It turned out, though, to be fairly difficult to make
that definition rigorous enough to go in the standard.

What the standard now says is that complex is required to work for
float, double, and long double; which other types it works for is up
to the library implementor.  This isn't really a new restriction, just
a clarification of the existing situation.

This problem isn't specific to complex, of course: many standard
library components are templates, and in each case the standard had
better describe which types the user may instantiate them with.
Several of these situations were clarified at the Stockholm meeting.
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: vandevod@cs.rpi.edu (David Vandevoorde)
Date: 1996/07/25
Raw View
>>>>> "JK" == James Kanze <kanze@lts.sel.alcatel.de> writes:
[...]
JK> I can see the potential problems of specifying the type
JK> constraints exactly.  However, would it be to much to ask that the
JK> standard contain words to the effect that the intent is for the
JK> template to work for user defined types modelling real numbers, or
JK> something along these lines.  If I understand what has just been
JK> said, it is sufficient for the implementation to provide the three
JK> specializations, without a general template at all.

One of the goals of the Stockholm meeting (which partially failed) was
to get ready with the second committee draft (CD2). From that viewpoint,
the subgroup dealing with numerics looked for minimal effort/maximum
safety solutions to tie up loose ends without creating new ones (this
is my personal interpretation and may not reflect the views of the
other people in that group).

Sometimes this meant pruning items that seemed to have feasible fixes
when the projected time-investment for those fixes seemed prohibitive
(e.g., this `complex' issue). For other items (e.g., various valarray
issues I raised), it meant not touching the DWP because the existing
wording was precise and self-consistent (even though, IMO, relatively
useless).

As I remember the discussion in the lib-3 working group, however, I
thought complex<valarray<float> >,  complex<valarray<double> > and
complex<valarray<long double> > were also to be supported?

 Daveed
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: kanze@lts.sel.alcatel.de (James Kanze US/ESC 60/3/141 #40763)
Date: 1996/07/25
Raw View
In article <fxtlog9l5ek.fsf@isolde.mti.sgi.com> Matt Austern
<austern@sgi.com> writes:

|> What the standard now says is that complex is required to work for
|> float, double, and long double; which other types it works for is up
|> to the library implementor.  This isn't really a new restriction, just
|> a clarification of the existing situation.

I can see the potential problems of specifying the type constraints
exactly.  However, would it be to much to ask that the standard contain
words to the effect that the intent is for the template to work for user
defined types modelling real numbers, or something along these lines.
If I understand what has just been said, it is sufficient for the
implementation to provide the three specializations, without a general
template at all.
--
James Kanze         Tel.: (+33) 88 14 49 00        email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
Conseils,    tudes et r   alisations en logiciel orient    objet --
                -- A la recherche d'une activit    dans une region francophone
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: Matt Austern <austern@isolde.mti.sgi.com>
Date: 1996/07/26
Raw View
vandevod@cs.rpi.edu (David Vandevoorde) writes:

> As I remember the discussion in the lib-3 working group, however, I
> thought complex<valarray<float> >,  complex<valarray<double> > and
> complex<valarray<long double> > were also to be supported?

That's not what the motion ended up saying: the actual wording reads
"The effect of instantiating the template complex for any type other
than float, double, or long double is unspecified."

I agree that this is quite restrictive, and I hope that most
implementors will allow other types.  In particular, complex integers
are sometimes useful.
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: vandevod@cs.rpi.edu (David Vandevoorde)
Date: 1996/07/27
Raw View
>>>>> "WG" == Wade Guthrie <wade@nb.rockwell.com> writes:

WG> vandevod@cs.rpi.edu (David Vandevoorde) writes:
>> The effect of instantiating the template `complex' for any type
>> other than float, double or long double is unspecified.

WG> This has probably been hashed to death but why is a complex<int>
WG> or complex<long> (etc.) not specified?

Because it was felt it would take too much time/effort to 1) decide
which complex operations (sine? magnitude? power? division?) apply to
integral complex types and 2) satisfactorily describe _what_ these
operations mean. (Again, this is my interpretation of the
discussions and others present may not agree.)

BTW, I'm interested in hearing from applications that rely on
complex<int> or complex<long>?

 Daveed
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: wade@nb.rockwell.com (Wade Guthrie)
Date: 1996/07/27
Raw View
vandevod@cs.rpi.edu (David Vandevoorde) writes:

>This has been clarified in Stockholm; the following text was added
>to the draft:

>   The effect of instantiating the template `complex' for any type
>   other than float, double or long double is unspecified.

This has probably been hashed to death but why is a complex<int> or
complex<long> (etc.) not specified?
--
Wade Guthrie                     |
wade@nb.rockwell.com             |
I don't speak for Rockwell.      |  Sucks Syntax.
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: vandevod@cs.rpi.edu (David Vandevoorde)
Date: 1996/07/22
Raw View
>>>>> "JB" == Joe Buck <jbuck@Synopsys.COM> writes:
[...]
JB> complex is a template; one can have complex<float> and
JB> complex<double>, but also of any other type that has the
JB> arithmetic operations defined.
[...]

This has been clarified in Stockholm; the following text was added
to the draft:

   The effect of instantiating the template `complex' for any type
   other than float, double or long double is unspecified.

A few more modifications were made to the <complex> specs, mostly
to clarify the definitions of potentially multivalued functions.

 Daveed
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: Norbert Schenk <schenk@Graphics.CS.Uni-Bonn.DE>
Date: 1996/07/16
Raw View
Could some kind soul shed some light on the subject of
complex numbers in C++? Every modern compiler seems
to have some kind of <complex.h>, but they are
never exactly the same. Has this already been
standardized? If not, are there any efforts and
how far did they go?

Thanks for all input!

------------------------------------------------------------------------------
Norbert Schenk
Computer Graphics
Dept. of Computer Science,               tel:   +49 228 550-391
University of Bonn                       fax:   +49 228 550-382
Roemerstr. 164,                          Email: schenk@graphics.cs.uni-bonn.de
D-53117 Bonn, Germany/Europe
------------------------------------------------------------------------------

---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson)
Date: 1996/07/17
Raw View
Norbert Schenk <schenk@Graphics.CS.Uni-Bonn.DE> writes:

>Could some kind soul shed some light on the subject of
>complex numbers in C++? Every modern compiler seems
>to have some kind of <complex.h>, but they are
>never exactly the same. Has this already been
>standardized? If not, are there any efforts and
>how far did they go?

The ANSI/ISO C++ committee's draft working paper includes a definition
of complex numbers -- see section 26.2 [lib.complex.numbers].  (The
committee's working paper is available on the net, see the comp.std.c++
FAQ list for the URL.)  I haven't really been following that part of
the standard, so I don't know how stable it is, and I also don't know
if there are any implementations which conform to that part of the
draft yet.

--
Fergus Henderson <fjh@cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3         |     -- the last words of T. S. Garp.
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: jbuck@Synopsys.COM (Joe Buck)
Date: 1996/07/17
Raw View
Norbert Schenk <schenk@Graphics.CS.Uni-Bonn.DE> writes:
>Could some kind soul shed some light on the subject of
>complex numbers in C++?

The draft ANSI/ISO C++ standard specifies a standard complex number class.
GNU C++ provides an implementation of this standard class, as do some
other compilers.  The draft standard says that you include <complex>,
not <complex.h>.

complex is a template; one can have complex<float> and complex<double>,
but also of any other type that has the arithmetic operations defined.
Typically your compiler supplier will provide pre-compiled specializations
for complex<float> and complex<double> (GNU C++ does).

The April 1995 draft working paper is on the web.  See

http://www.cygnus.com/misc/wp/draft/lib-numerics.html#lib.complex.numbers

--
-- Joe Buck  <jbuck@synopsys.com> (not speaking for Synopsys, Inc)

Work for something because it is good,
not just because it stands a chance to succeed.    -- Vaclav Havel
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]