News for hackers. Stuff that matters.
Re:Ask HN: What was the worst bug you've ever solved ? by tlb on Friday October 09, 2009 @01:51PM (#872033)
For example, a function might be inlined at some call sites and not inlined at others. Inlined versions might carry 80 bits through the result, but non-inlined version are truncated to 64. So in:

  double foo(double x) { return x*3.3; }
  double bar1(double x) { return foo(x); }
  double bar2(double x) { return foo(x); }
  void t_bar(double x) { assert(bar1(x) == bar2(x)); }
t_bar can fail depending on how bar1 and bar2 are compiled.
Re:Ask HN: What was the worst bug you've ever solved ? by tudorachim on Friday October 09, 2009 @02:15PM (#872094)
I'm not sure how the example could make the assertion fail; I think that the point is that if 3.3 is treated as a long double by the compiler, then the result of x*3.3 will be a long double, which is more precise than the double returned by foo; but, regardless of how bar1 and bar2 are compiled, they both make a call to foo() which returns a double. Is it the case then that the behavior depends on how foo is compiled? I don't see how else the 80-bit result could propagate to the test for equality.
Re:Ask HN: What was the worst bug you've ever solved ? by tlb on Friday October 09, 2009 @02:28PM (#872131)
returning a double can be optimized into returning an 80-bit result in a register. If this happens with bar1 but not bar2, then you get different results.