Floating Point + Threads?

Iain Buclaw ibuclaw at ubuntu.com
Sat Apr 16 11:43:41 PDT 2011


== Quote from Walter Bright (newshound2 at digitalmars.com)'s article
> On 4/16/2011 6:46 AM, Iain Buclaw wrote:
> > == Quote from Walter Bright (newshound2 at digitalmars.com)'s article
> >> That's a good thought. FP addition results can differ dramatically depending on
> >> associativity.
> >
> > And not to forget optimisations too. ;)
> The dmd optimizer is careful not to reorder evaluation in such a way as to
> change the results.

And so it rightly shouldn't!

I was thinking more of a case of FPU precision rather than ordering: as in you get
a different result computing on SSE in double precision mode on the one hand, and
by computing on x87 in double precision then writing to a double variable in memory.


Classic example (which could either be a bug or non-bug depending on your POV):

void test(double x, double y)
{
  double y2 = x + 1.0;
  assert(y == y2);   // triggers with -O
}

void main()
{
  double x = .012;
  double y = x + 1.0;
  test(x, y);
}



More information about the Digitalmars-d mailing list