[Issue 6098] New: CTFE static array corruption of data

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jun 3 06:20:13 PDT 2011


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

           Summary: CTFE static array corruption of data
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: andrej.mitrovich at gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2011-06-03 06:15:46 PDT ---
import std.math;
import std.stdio;
import std.range;

auto makeSine(int TableSize)()
{
    double[TableSize] result;
    // double[] result = new double[](TableSize);  // this fixes the issue

    foreach (index, ref sample; result)
    {
        sample = cast(double)sin((cast(double)index / cast(double)TableSize) *
PI * 2.);
    }
    writeln(result);
    return cycle(result);
}

void main()
{    
    auto sineTable = makeSine!(10);

    writeln(take(sineTable, 10));
    writeln(take(sineTable, 10));

    double[] arr;
    foreach (sample; take(sineTable, 10))
    {
        arr ~= sample;
    }
    writeln(arr);
}

Results:
[0, 0.587785, 0.951057, 0.951057, 0.587785, -5.42101e-20, -0.587785, -0.951057,
-0.951057, -0.587785]
[6.14906e-318, 2.59842e-307, 2.31044e-317, 0.951057, 0.587785, -5.42101e-20,
2.64149e-308, 2.08636e-317, 1.82805e-307, 2.641e-308]
[6.14906e-318, 2.59842e-307, 2.31044e-317, 2.59842e-307, 2.31044e-317,
-5.42101e-20, 2.64149e-308, 2.08636e-317, 1.82805e-307, 2.641e-308]
[6.14906e-318, 2.64128e-308, 2.49803e-307, 2.2817e-314, 6.3666e-314,
-5.42101e-20, 2.64149e-308, -nan, 1.82805e-307, 2.64126e-308]

If bugzilla makes it hard to read I've pasted the results here:
http://paste.pocoo.org/show/400027/

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list