www.digitalmars.com         C & C++   DMDScript  

D - complex problems with sqrt

reply Helmut Leitner <helmut.leitner chello.at> writes:
This programm

import venus.all;

int main (char [][] args)
{
    float y=3.14;
    PrintLine("y=",y);
    cfloat cy=3.14 + 10i;
    PrintLine("cy.re=",cy.re);
    PrintLine("cy.im=",cy.im);
    PrintLine("cy=",cy);
    ifloat ix=1.5i;
    PrintLine("ix=",ix);
    cdouble z=cy*ix;
    PrintLine("z=",z);
    z=sqrt(z);
    PrintLine("sqrt(z)=",z);
    z= -1;
    PrintLine("z=",z);
    z=sqrt(z);
    PrintLine("sqrt(z)=",z);
    return 0;
}

Will produce the following output:

y=3.140000                           ok, only testing
cy.re=3.140000                       ok  
cy.im=10.000000                      ok  
cy=3.140000 + 10.000000i             ok, testing PrintLine for cfloat
ix=1.500000i                         ok, ifloat assignment
z=-15.000000 + 4.710000i             ok, multiplication 
sqrt(z)=2.170253 + 0.000000i         nok sqrt
z=-1.000000 + 0.000000i              ok, cdouble assignment
sqrt(z)=-nan + 0.000000i             nok sqrt

The sqrt values calculated are in error. I don't no why sqrt is called at all. 
It seams that Phobos doesn't define a complex version for sqrt. The stdio and
stdlib modules are imported, but they shouldn't match.

--
Helmut Leitner    leitner hls.via.at   
Graz, Austria   www.hls-software.com
Apr 21 2003
parent reply "Walter" <walter digitalmars.com> writes:
That's true, the various math functions for complex arguments haven't been
implemented yet. -Walter

"Helmut Leitner" <helmut.leitner chello.at> wrote in message
news:3EA4439C.135F6C1C chello.at...
 This programm

 import venus.all;

 int main (char [][] args)
 {
     float y=3.14;
     PrintLine("y=",y);
     cfloat cy=3.14 + 10i;
     PrintLine("cy.re=",cy.re);
     PrintLine("cy.im=",cy.im);
     PrintLine("cy=",cy);
     ifloat ix=1.5i;
     PrintLine("ix=",ix);
     cdouble z=cy*ix;
     PrintLine("z=",z);
     z=sqrt(z);
     PrintLine("sqrt(z)=",z);
     z= -1;
     PrintLine("z=",z);
     z=sqrt(z);
     PrintLine("sqrt(z)=",z);
     return 0;
 }

 Will produce the following output:

 y=3.140000                           ok, only testing
 cy.re=3.140000                       ok
 cy.im=10.000000                      ok
 cy=3.140000 + 10.000000i             ok, testing PrintLine for cfloat
 ix=1.500000i                         ok, ifloat assignment
 z=-15.000000 + 4.710000i             ok, multiplication
 sqrt(z)=2.170253 + 0.000000i         nok sqrt
 z=-1.000000 + 0.000000i              ok, cdouble assignment
 sqrt(z)=-nan + 0.000000i             nok sqrt

 The sqrt values calculated are in error. I don't no why sqrt is called at
all.
 It seams that Phobos doesn't define a complex version for sqrt. The stdio
and
 stdlib modules are imported, but they shouldn't match.

 --
 Helmut Leitner    leitner hls.via.at
 Graz, Austria   www.hls-software.com
Apr 22 2003
parent reply Helmut Leitner <leitner hls.via.at> writes:
Walter wrote:
 
 That's true, the various math functions for complex arguments haven't been
 implemented yet. -Walter
 
No problem. But why do the calls match? -- Helmut Leitner leitner hls.via.at Graz, Austria www.hls-software.com
Apr 22 2003
parent reply "Walter" <walter digitalmars.com> writes:
"Helmut Leitner" <leitner hls.via.at> wrote in message
news:3EA56AF0.437F70A hls.via.at...
 Walter wrote:
 That's true, the various math functions for complex arguments haven't
been
 implemented yet. -Walter
No problem. But why do the calls match?
Both are a conversion.
Apr 22 2003
next sibling parent Andy Friesen <andy ikagames.com> writes:
Walter wrote:
 "Helmut Leitner" <leitner hls.via.at> wrote in message
 news:3EA56AF0.437F70A hls.via.at...
 
Walter wrote:

That's true, the various math functions for complex arguments haven't
been
implemented yet. -Walter
No problem. But why do the calls match?
Both are a conversion.
It may be worth the hassle to disallow floating points to be converted to integers, in that case. round/floor/truncate functions could fill the gap. (make it/them intrinsic?)
Apr 22 2003
prev sibling parent Helmut Leitner <helmut.leitner chello.at> writes:
Walter wrote:
 
 "Helmut Leitner" <leitner hls.via.at> wrote in message
 news:3EA56AF0.437F70A hls.via.at...
 Walter wrote:
 That's true, the various math functions for complex arguments haven't
been
 implemented yet. -Walter
No problem. But why do the calls match?
Both are a conversion.
I don't understand that. I can't find anything about conversions in the language specs that would back that. Anyway nothing that would make a complex number match to the only //intrinsic.d real sqrt(real); I can find. Even if there were something it would be just plain wrong. -- Helmut Leitner leitner hls.via.at Graz, Austria www.hls-software.com
Apr 22 2003