www.digitalmars.com         C & C++   DMDScript  

D - Disappointing

reply Helmut Leitner <helmut.leitner chello.at> writes:
On Apr 6 2003 I wrote to Walter Bright:
 
 Walter,
 
 a number of floating point type arrays don't sort correctly under certain
 circumstances. This is the code:
 
 class TypeInfo_d : TypeInfo
 {
  ...
     int compare(void *p1, void *p2)
     {
         return *(double *)p1 - *(double *)p2;
     }
  ...
 }
 
 When values are small (I tried to sort uSecond timings like the following):
 
    sectab[0] 0.0000070792
    sectab[1] 0.0000072514
    sectab[2] 0.0000066818
    sectab[3] 0.0000067485
    sectab[4] 0.0000066986
    sectab[5] 0.0000068492
    sectab[6] 0.0000066601
    sectab[7] 0.0000065775
    sectab[8] 0.0000068234
    sectab[9] 0.0000067371
    sectab[10] 0.0000067350
 
 rounding will make the return value unusable and the array remains unsorted.
 I think similar problems would turn up, when numbers are too large for the
 int range.
 
 The typical construction that you use in other places, will avoid the problem:
 
    type a = *(type *) p1;
    type b = *(type *) p2;
    return a < b ? -1 : a > b ? 1 : 0;
 
 ...

I can't understand why there was no release fixing the bug in the meantime. -- Helmut Leitner leitner hls.via.at Graz, Austria www.hls-software.com
May 03 2003
parent "Walter" <walter digitalmars.com> writes:
"Helmut Leitner" <helmut.leitner chello.at> wrote in message
news:3EB3B096.838DB3BB chello.at...
 I can't understand why there was no release fixing the bug in the

Because I'm trying to get the linux version working. In the meantime, you can apply the workaround you specified. I apologize.
May 03 2003