[Issue 692] New: rules for assigning to complex types are too strict

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Dec 16 21:24:44 PST 2006


http://d.puremagic.com/issues/show_bug.cgi?id=692

           Summary: rules for assigning to complex types are too strict
           Product: D
           Version: 0.177
          Platform: All
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: wbaxter at gmail.com


//You can assign ints and floats and doubles to a double with no
//problem.  Even arrays work.
void test1() {
    // All ok
    double a = 0;
    double b = 0.0;
    double c = 0.0f;
    double[] d = [0];
    double[] e = [0.0];
    double[] f = [0.0f];
}

//But there's very little that can be assigned to a cdouble:
void test2()
{
    // All errors
    cdouble a = 0;
    cdouble b = 0i;
    cdouble c = 0.0;
    cdouble d = 0.0f;
    cdouble e = 0.0fi;
    cdouble[] f = [0];
}

//Yet, it is ok to add many things to a cdouble.
void test3()
{
    // All ok:
    cdouble a = 0+0i;
    cdouble b = a + 0;
    cdouble c = a + 0i;
    cdouble d = a + 0.0;
    cdouble e = a + 0.0f;
    cdouble f = a + 0.0fi;
}


I don't see any good reason for this strictness.  I suspsect nobody's
complained simply because few current users actually touch complex types.

Real world impact:
In writing a generic BLAS/LAPACK-backed nd-array class I find that many of my
generic test cases have to contain sillyness like:
        T z = cast(T)0;
        A = [[z+ 5, z+ 1, z+ 2],
             [z+ 3, z+ 4, z+ 5],
             [z+ 6, z+ 7, z+ 8]];
        x =  [z+ 1, z+ 2, z+ 3];
        b = mult(A,x);

just to handle complex types without generating compiler errors.


-- 



More information about the Digitalmars-d-bugs mailing list