Topic: complex problem


Author: "Roger L. Cauvin" <rcauvin@natinst.com>
Date: 1996/09/19
Raw View
Barry Margolin <barmar@bbnplanet.com> wrote in article
<51kfqh$a8c@tools.bbnplanet.com>...

> No access is provided to individually set the sign, mantissa, or exponent
> of floats, but this doesn't seem to hinder programs that use this data
> type.  Complex numbers should be used similarly.

Float is a built-in type; complex is a class.  If float were a class it is
quite conceivable that it would have member functions allowing the setting
of the sign, mantissa, and exponent without exposing implementation
details.
Having a SetSign member function, for instance, certainly wouldn't violate
encapsulation.

Incidently, operator- allows toggling of the sign of a float.

Roger

---

Roger L. Cauvin
rcauvin@natinst.com
Software Engineeer
National Instruments
---
[ 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: sean@delta.com (Sean L. Palmer)
Date: 1996/09/20
Raw View

> The complex class (as exemplified by libg++-2.7.2) makes the
> underlying real and imaginary components private.  No access is
> provided to individually set them.

Please as well require (or strongly suggest?) this of simple classes (such
as that for complex<> or for some class that consists solely of an int data
member and some functions and constructors)

Where the compiler would optimize temporaries of the underlying types of
the data members, it should also optimize temporaries of the class itself.
Namely, NOT making superfluous copies of it on the stack or initializing
data members that never get used. Just because it's a class shouldn't
change the code generation, ESPECIALLY if there is no defined destructor.
I've been having serious problems with this when making a fixed point class
and 2d and 3d point classes (which are essentially the same thing as class
complex). Yes I'm providing them with the correct semantics and such. This
is with Watcom 10.6, considered the BEST optimizing compiler hands down for
the DOS/Windows platform. Yes I've reported it to them.

It is really too bad that classes ARE NOT given the same properties as the
underlying fundamental data types they're made of. They are merely a
collection of values unless an address is taken of the object, in which
case you'd have to use struct semantics. But if the address is never taken
or used, a compiler should be able to put all data members exclusively into
registers if it can.

I realize this may be a 'quality of implementation' issue, but I thought
the intent of C++ was to make classes as compatible with builtin types as
possible. This should apply to code generation as well.

> Please give this serious consideration.

This also.



[ 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: Barry Margolin <barmar@bbnplanet.com>
Date: 1996/09/20
Raw View
In article <01bba64f$818f4ce0$e60ca482@tecra.natinst.com>,
Roger L. Cauvin <rcauvin@natinst.com> wrote:
>Incidently, operator- allows toggling of the sign of a float.

No it doesn't.  It returns a new float with the opposite sign of its
parameter.
--
Barry Margolin
BBN Planet, Cambridge, MA
barmar@bbnplanet.com -  Phone (617) 873-3126 - Fax (617) 873-6351
(BBN customers, please call (800) 632-7638 option 1 for support)
---
[ 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: rmashlan@r2m.com (Robert Mashlan)
Date: 1996/09/20
Raw View
"Roger L. Cauvin" <rcauvin@natinst.com> wrote:

>Incidently, operator- allows toggling of the sign of a float.

Not exactly.   afloat *= -1.0 would toggle the sign, however unary -
would return a value that is a copy of the operand with the sign
toggled.



---
Robert Mashlan  R2M Software  rmashlan@r2m.com
Internet Resources for Windows Developers http://www.r2m.com/windev/
---
[ 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: jbuck@Synopsys.COM (Joe Buck)
Date: 1996/09/21
Raw View

clamage@taumet.Eng.Sun.COM (Steve Clamage) wrote:
>>For complex variable z1 you can write, for example
>> z1 = complex(new_real_part, z1.imag());
>>The overhead should be somewhere between zero and small compared to
>> z1.set_real(new_real_part);

Christian Millour <chris161@speedy.grolier.fr> writes:
>I'm not familiar with optimisation techniques and cannot figure how
>this overhead could be zero. Could you please sketch the main steps ?

(Let's pretend complex is a normal class, not a template: think of
this as complex<double>).  This is in principle very easy for the compiler.

First the compiler will see

 struct complex tmp; // saying "struct" because no constructor
 tmp.real_ = new_real_part;
 tmp.imag_ = z1.imag_;
 z1.real_ = tmp.real;
 z1.imag_ = tmp.imag_;

Now the compiler eliminates the temporary by replacing its use by its value:

 z1.real_ = new_real_part;
 z1.imag_ = z1.imag_;

Finally the redundant assignment is eliminated.

 z1.real_ = new_real_part;

Unfortunately several compilers (e.g. g++, SunSoft's C++) don't manage
to do this well, since even after inlining a function with a reference
to complex, they still try to pass the complex through memory, leaving
redundant stores behind.  But that could be fixed.

--
-- Joe Buck http://www.synopsys.com/pubs/research/people/jbuck.html

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 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: Barry Margolin <barmar@bbnplanet.com>
Date: 1996/09/16
Raw View
In article <u9685ehca5.fsf_-_@chekov.ctd.comsat.com>,
Neal Becker  <neal@ctd.comsat.com> wrote:
>The complex class (as exemplified by libg++-2.7.2) makes the
>underlying real and imaginary components private.  No access is
>provided to individually set them.

No access is provided to individually set the sign, mantissa, or exponent
of floats, but this doesn't seem to hinder programs that use this data
type.  Complex numbers should be used similarly.
--
Barry Margolin
BBN Planet, Cambridge, MA
barmar@bbnplanet.com -  Phone (617) 873-3126 - Fax (617) 873-6351
(BBN customers, please call (800) 632-7638 option 1 for support)


[ 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: clamage@taumet.Eng.Sun.COM (Steve Clamage)
Date: 1996/09/17
Raw View
In article @chekov.ctd.comsat.com, Neal Becker <neal@ctd.comsat.com> writes:
>The complex class (as exemplified by libg++-2.7.2) makes the
>underlying real and imaginary components private.  No access is
>provided to individually set them.

For complex variable z1 you can write, for example
 z1 = complex(new_real_part, z1.imag());
The overhead should be somewhere between zero and small compared to
 z1.set_real(new_real_part);

>Here's my suggestion:
>
>FLOAT& real() ...
>FLOAT& imag() ...
>
>returns ref's to the underlying real & imag components, so you can
>assign to them.

That would require that complex numbers always have a Cartesian
reprsentation, which is not currently required.

---
Steve Clamage, stephen.clamage@eng.sun.com
---
[ 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: Christian Millour <chris161@speedy.grolier.fr>
Date: 1996/09/19
Raw View
clamage@taumet.Eng.Sun.COM (Steve Clamage) wrote:
>In article @chekov.ctd.comsat.com, Neal Becker <neal@ctd.comsat.com> writes:
>>The complex class (as exemplified by libg++-2.7.2) makes the
>>underlying real and imaginary components private.  No access is
>>provided to individually set them.
>
>For complex variable z1 you can write, for example
> z1 = complex(new_real_part, z1.imag());
>The overhead should be somewhere between zero and small compared to
> z1.set_real(new_real_part);
>
I'm not familiar with optimisation techniques and cannot figure how
this overhead could be zero. Could you please sketch the main steps ?

TIA,

--chris
---
[ 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: Neal Becker <neal@ctd.comsat.com>
Date: 1996/09/16
Raw View
The complex class (as exemplified by libg++-2.7.2) makes the
underlying real and imaginary components private.  No access is
provided to individually set them.

My experience is that this will seriously hamper attempts to use this
class to replace older code.  I just had to give up on porting an FFT
routine.

Please include code to set real and imaginary components.  Without
this the complex class will be useless for porting a large part of
legacy software.

Here's my suggestion:

FLOAT& real() ...
FLOAT& imag() ...

returns ref's to the underlying real & imag components, so you can
assign to them.

Please give this serious consideration.
---
[ 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
]