std.math.pow produces incorrect results when used with std.parallelism

finalpatch fengli at gmail.com
Sat Jun 1 22:17:12 PDT 2013


the following code compiled with GDC shows the bug
(I'm using the gcc 4.8 windows mingw32 version from 
https://bitbucket.org/goshawk/gdc/downloads)

import std.math;
import std.stdio;
import std.range;
import std.parallelism;

void main()
{
     enum n = 1000;
     float step = 1.0f/n;

     float[n] results_singlethreaded;
     float[n] results_multithreaded;

     foreach(i; iota(n))
         results_singlethreaded[i] = pow(step * i, 0.4545f);
     foreach(i; parallel(iota(n)))
         results_multithreaded[i] = pow(step * i, 0.4545f);
     foreach(i; iota(n))
         assert(results_singlethreaded[i] == 
results_multithreaded[i]);
}

~/Desktop $ ./test.exe
core.exception.AssertError at test.d(26): Assertion failure

The same code passes without assertion when compiled with DMD.


More information about the D.gnu mailing list