diff -uNr dmd-0.130/dmd/src/dmd/constfold.c dmd-0.131/dmd/src/dmd/constfold.c --- dmd-0.130/dmd/src/dmd/constfold.c 2005-08-26 00:49:06.000000000 +0200 +++ dmd-0.131/dmd/src/dmd/constfold.c 2005-09-08 19:12:40.000000000 +0200 @@ -310,9 +310,9 @@ assert(0); } else - { integer_t n1; - integer_t n2; - integer_t n; + { sinteger_t n1; + sinteger_t n2; + sinteger_t n; n1 = e1->toInteger(); n2 = e2->toInteger(); @@ -345,9 +345,9 @@ assert(0); } else - { integer_t n1; - integer_t n2; - integer_t n; + { sinteger_t n1; + sinteger_t n2; + sinteger_t n; n1 = e1->toInteger(); n2 = e2->toInteger(); diff -uNr dmd-0.130/dmd/src/dmd/mars.c dmd-0.131/dmd/src/dmd/mars.c --- dmd-0.130/dmd/src/dmd/mars.c 2005-08-09 23:55:34.000000000 +0200 +++ dmd-0.131/dmd/src/dmd/mars.c 2005-09-08 19:11:24.000000000 +0200 @@ -49,7 +49,7 @@ copyright = "Copyright (c) 1999-2005 by Digital Mars"; written = "written by Walter Bright"; - version = "v0.130"; + version = "v0.131"; global.structalign = 8; memset(¶ms, 0, sizeof(Param)); diff -uNr dmd-0.130/dmd/src/phobos/std/math.d dmd-0.131/dmd/src/phobos/std/math.d --- dmd-0.130/dmd/src/phobos/std/math.d 2005-09-06 16:06:54.000000000 +0200 +++ dmd-0.131/dmd/src/phobos/std/math.d 2005-09-09 01:57:32.000000000 +0200 @@ -839,140 +839,11 @@ return fabs(x - y) <= precision; } -/******************************************* - * Submitted by Don Clugston - * http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/27735 - * - * "How equal" are two reals x and y? - * Returns the number of mantissa bits which are equal in x and y; - * this is similar to the concept of "significant figures". - * For example, 0x1.F8p+60 and 0x1.F1p+60 are equal to 5 bits of precision. - * If x==y, then precisionEquality(a,b) == real.mant_dig. - * - * If x and y differ by a factor of two or more, then they have no - * bits in common, so this function returns a value which is <=0. - * Returns 0 if they differ by a factor of >=2 but < 4, - * returns 1 for factors >=4 but <8, etc. - * - * If the numbers have opposite sign, the difference in orders - * of magnitude is based on the IEEE binary encoding. - * For example, -1 and +1 differ by half the number line. - * - * Pretend the numbers were fixed point. In the IEEE extended format, - * there are about 32768 digits in front of the decimal point, and - * the same number behind. But only the first 64 bits after the first '1' - * bit are recorded. - * - * If the exponents are different, then the return value - * is negative, and gives the number of (binary) orders of - * magnitude of difference between a and b. - */ - private int iabs(int i) { return i >= 0 ? i : -i; } -int precisionEquality(real a, real b) -{ - real diff = a-b; - ushort *pa = cast(ushort *)(&a); - ushort *pb = cast(ushort *)(&b); - ushort *pd = cast(ushort *)(&diff); - - // The difference in exponent between 'a' and 'a-b' - // is equal to the number of mantissa bits of a which are - // equal to b. If the difference is negative, then a and b - // have different exponents. If it is positive, then a and b - // are equal to that number of decimal places. - // AND with 0x7FFF to form the absolute value. - // Subtract 1 so that we round downwards. - int bitsdiff = ( ((pa[4]&0x7FFF) + (pb[4]&0x7FFF)-1)>>1) - (pd[4]&0x7FFF); - - if ((pd[4]&0x7FFF) == 0) // Difference is zero or denormal - { - if (a==b) - return real.mant_dig; - // 'diff' is denormal, so the number of equal bits is higher; - // we need to add the number of zeros that lie at the start of - // its mantissa. We do this by multiplying by 2^real.mant_dig - diff*=0x1p+63; - return bitsdiff + real.mant_dig-(pd[4]&0x7FFF); - } - - if (bitsdiff > 0) - return bitsdiff + 1; - - // Check for NAN or Infinity. - if (pd[4]&0x7FFF==0x7FFF) // Result is NAN or INF - { - if (a==b) // both were +INF or both were -INF. - { - return real.mant_dig; - } - if (isnan(diff)) - { - return -65535; // at least one was a NAN. - } - // fall through for comparisons of INF with large reals. - } - // Return the negative of the absolute value of - // the difference in exponents. - - if ((pa[4]^pb[4])&0x8000) // do they have opposite signs? - { // Convert the 'offset' exponent format to twos-complement, - // then do a normal subtraction. - return 1-iabs(pa[4]-(0x8000-pb[4])); - } - return 1-iabs(pa[4]-pb[4]); -} - -unittest -{ - // Exact equality - assert(precisionEquality(real.max,real.max)==real.mant_dig); - assert(precisionEquality(0,0)==real.mant_dig); - assert(precisionEquality(7.1824,7.1824)==real.mant_dig); - assert(precisionEquality(real.infinity,real.infinity)==real.mant_dig); - - // one bit off exact equality - assert(precisionEquality(1+real.epsilon,1)==real.mant_dig-1); - assert(precisionEquality(1,1+real.epsilon)==real.mant_dig-1); - // one bit below. Must round off correctly when exponents are different. - assert(precisionEquality(1,1-real.epsilon)==real.mant_dig-1); - assert(precisionEquality(1-real.epsilon,1)==real.mant_dig-1); - assert(precisionEquality(-1-real.epsilon,-1)==real.mant_dig-1); - assert(precisionEquality(-1+real.epsilon,-1)==real.mant_dig-1); - - // Numbers that are close - assert(precisionEquality(0x1.Bp+5, 0x1.B8p+5)==5); - assert(precisionEquality(0x1.8p+10, 0x1.Cp+10)==2); - assert(precisionEquality(1, 1.1249)==4); - assert(precisionEquality(1.5, 1)==1); - - // Extreme inequality - assert(precisionEquality(real.nan,0)==-65535); - assert(precisionEquality(0,-real.nan)==-65535); - assert(precisionEquality(real.nan,real.infinity)==-65535); - assert(precisionEquality(real.infinity,-real.infinity)==-65533); - assert(precisionEquality(-real.max,real.infinity)==-65532); - assert(precisionEquality(-real.max,real.max)==-65531); - - // Numbers that are half the number line apart - // Note that (real.max_exp-real.min_exp) = 32765 - assert(precisionEquality(-real.max,0)==-32765); - assert(precisionEquality(-1,1)==-32765); - assert(precisionEquality(real.min,1)==-16381); - - // Numbers that differ by one order of magnitude - assert(precisionEquality(real.max,real.infinity)==0); - assert(precisionEquality(1, 2)==0); - assert(precisionEquality(2, 1)==0); - assert(precisionEquality(1.5*(1-real.epsilon), 1)==2); - assert(precisionEquality(4*(1-real.epsilon), 1)==0); - assert(precisionEquality(4, 1)==-1); -} - /************************************** int feqrel(real x, real y)