www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript
electronics



c++ - possible error in dmc complex arithmetic

↑ ↓ ← John Smith <bystander shaw.ca> writes:
1.2 + .5i ^ -.9 + 1.5i = 0.436466 + 0.0166961i

dmc (C, not C++) exponentiation with these operands gives the result:

1.2 + .5i ^ -.9 + 1.5i = 0.436466 + 0.000000i

bug?

JS
Sep 25 2007
↑ ↓ Walter Bright <newshound1 digitalmars.com> writes:
John Smith wrote:
 1.2 + .5i ^ -.9 + 1.5i = 0.436466 + 0.0166961i
 
 dmc (C, not C++) exponentiation with these operands gives the result:
 
 1.2 + .5i ^ -.9 + 1.5i = 0.436466 + 0.000000i
 
 bug?

Can't tell without a complete source code example exhibiting the behavior.
Sep 27 2007
↑ ↓ John Smith <bystander shaw.ca> writes:
#include <stdio.h>
#include <complex.h>

int main(void)
{
	/* declaration */
    //double _Complex z1, z2, z3;
    double complex z1, z2, z3;

    /* assignment */
    z1 = 1.2 + .5 * I;
    z2 = -.9 + 1.5 * I;

    /* arithmetic operators */
    z3 = z1 + z2;
    printf("z1+z2 = %g %gi\n", creal(z3), cimag(z3));
    z3 = z1 - z2;
    printf("z1-z2 = %g %gi\n", creal(z3), cimag(z3));
    z3 = z1 * z2;
    printf("z1*z2 = %g %gi\n", creal(z3), cimag(z3));
    z3 = z1 / z2;
    printf("z1/z2 = %g %gi\n", creal(z3), cimag(z3));

    /* functions */
    z3 = csqrt(z1);
    printf("sqrt = %g %gi\n", creal(z3), cimag(z3));
    z3 = cpow(z1, z2);
    printf("z1^z2 = %g %fi\n", creal(z3), cimag(z3));

    return 0;
}
Oct 01 2007
↑ ↓ John Smith <bystander shaw.ca> writes:
== Quote from John Smith (bystander shaw.ca)'s article
 #include <stdio.h>
 #include <complex.h>
 int main(void)
 {
 	/* declaration */
     //double _Complex z1, z2, z3;
     double complex z1, z2, z3;
     /* assignment */
     z1 = 1.2 + .5 * I;
     z2 = -.9 + 1.5 * I;
     /* arithmetic operators */
     z3 = z1 + z2;
     printf("z1+z2 = %g %gi\n", creal(z3), cimag(z3));
     z3 = z1 - z2;
     printf("z1-z2 = %g %gi\n", creal(z3), cimag(z3));
     z3 = z1 * z2;
     printf("z1*z2 = %g %gi\n", creal(z3), cimag(z3));
     z3 = z1 / z2;
     printf("z1/z2 = %g %gi\n", creal(z3), cimag(z3));
     /* functions */
     z3 = csqrt(z1);
     printf("sqrt = %g %gi\n", creal(z3), cimag(z3));
     z3 = cpow(z1, z2);
     printf("z1^z2 = %g %fi\n", creal(z3), cimag(z3));
     return 0;
 }

See incorrect result for cpow() JS
Oct 01 2007
↑ ↓ → Walter Bright <newshound1 digitalmars.com> writes:
Thank-you.
Oct 01 2007