www.digitalmars.com         C & C++   DMDScript  

D - Complex bug

reply "dickl" <dick221z yahoo.com> writes:
When casting using (idouble) to set the imaginary part of a complex double,
the imaginary part of a cdouble never gets set.

int main()
{

   double a=5;
   double b=-0.5;
   cdouble plx = a +b*1.0i;
   cdouble ply = a+ (idouble)b;
   printf("re:%f im:%f\n",plx.re,plx.im);
   printf("re:%f im:%f\n",ply.re,ply.im);

    return 1;
}

prints out   re:5.0 im:-0.5
                 re:5.0  im:0.0
Feb 19 2004
parent reply Manfred Nowak <svv1999 hotmail.com> writes:
On Thu, 19 Feb 2004 17:12:28 -0500, dickl wrote:

 When casting using (idouble) to set the imaginary part of a complex double,
 the imaginary part of a cdouble never gets set.

Confirmed but not a bug. Casting a number to idouble or double yields just the imaginary or the real part of that number. How else should that casts be defined? What should the result of `cast(idouble)(2+3i)' be? So long.
Feb 19 2004
parent reply "dickl" <dick221z yahoo.com> writes:
Ok,  but it makes it a little tedious to build a complex number from
individual variables.

It would be nice to have a way to say
cdouble var = a + (imaginary)b;



"Manfred Nowak" <svv1999 hotmail.com> wrote in message
news:c13se2$2pue$1 digitaldaemon.com...
 On Thu, 19 Feb 2004 17:12:28 -0500, dickl wrote:

 When casting using (idouble) to set the imaginary part of a complex


 the imaginary part of a cdouble never gets set.

Confirmed but not a bug. Casting a number to idouble or double yields just the imaginary or the real part of that number. How else should that casts be defined? What should the result of `cast(idouble)(2+3i)' be? So long.

Feb 20 2004
parent Manfred Nowak <svv1999 hotmail.com> writes:
dickl wrote:

[...]
 It would be nice to have a way to say
 cdouble var = a + (imaginary)b;

`cdouble var = a + b * 1i;' is even shorter. Why to introduce something special, that needs more effort? And dont forget the cast! In D the cast keyword is obligate. Only dmd is so kind to forget about that. So long.
Feb 21 2004