[Issue 1081] with using real and -O option, dmd generate bug code

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Mar 29 19:28:54 PDT 2007


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





------- Comment #3 from s180m at yahoo.co.jp  2007-03-29 21:28 -------
// a small example

import std.c.stdlib;
import std.math;
import std.outofmemory;

abstract final class Lanczos2 {
private:

  static int* s_table;

  static this(){
    s_table = cast(int*)malloc(int.sizeof * (2<<16));
    if(! s_table) _d_OutOfMemory();

    real t = 0.;
    for(int i=0;i<2<<16;i++){
      t += 1./65536.;
      s_table[i] = cast(int)round(
65536.*sin(PI*t)*sin(PI/2.*t)/((PI*PI/2.)*t*t) );
    }
    s_table[0] = 1<<16;
  }

public:

  static int opIndex(int a) {
    if((a <= -2<<16) || (a >= 2<<16)) return 0;
    if(a<0) a=-a;
    assert((0<=a)&&(a<2<<16));
    return s_table[a];
  }

}

void main(){
  int d;
  for(int i=-0x1abcd;i<0x20000;i+=0x10000){
    printf("%8x + %8x ",d,Lanczos2[i]);
    d += Lanczos2[i];
    printf(" = %8x\n",d);

  }
  if(0==d) printf("error A\n");
}


/**
 * >dmd -release -inline bug_opt.d
 * >bug_opt2.exe
 *        0 + fffff81e  = fffff81e
 * fffff81e +     5606  =     4e24
 *     4e24 +     cb79  =    1199d
 *    1199d + ffffea0f  =    103ac
 *
 *
 * >dmd -release -inline -O bug_opt.d
 * >bug_opt2.exe
 *        0 + 80000000  = 80000000
 * 80000000 + 80000000  =        0
 *        0 + 80000000  = 80000000
 * 80000000 + 80000000  =        0
 * error A
 *
 */


-- 



More information about the Digitalmars-d-bugs mailing list