www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - BUG: Sorting array of real's doesn't correctly sort things

reply Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
The following code (Linux, 0.102) demonstrates that an array of real's 
is not sorted correctly:

 import std.stdio;
                                                                               
 
 int main() {
   real[1000] array;
   for(int i=999; i>=0; i--)
     array[999-i] = (cast(real)i)/8;
                                                                               
 
   real[] sorted_copy = array.dup;
   sorted_copy.sort;
                                                                               
 
   for(int i=0; i<1000; i++)
     writef("%f\n", sorted_copy[i]);
                                                                               
 
   return 0;
 }

The first several lines of ouput are
 0.375000
 0.000000
 0.500000
 0.625000
 0.250000
 0.125000
 2.000000

Oct 11 2004
parent "Thomas Kuehne" <eisvogel users.sourceforge.net> writes:
Russ Lewis schrieb:
 The following code (Linux, 0.102) demonstrates that an array of real's
 is not sorted correctly:

 import std.stdio;

 int main() {
   real[1000] array;
   for(int i=999; i>=0; i--)
     array[999-i] = (cast(real)i)/8;

   real[] sorted_copy = array.dup;
   sorted_copy.sort;

   for(int i=0; i<1000; i++)
     writef("%f\n", sorted_copy[i]);

   return 0;
 }

The first several lines of ouput are
 0.375000
 0.000000
 0.500000
 0.625000
 0.250000
 0.125000
 2.000000


added to destress as svn://svn.kuehne.cn/dstress/run/sort_03.d in addition the following striped down code segfaults: # real[10] array; # real[] copy = array.dup; # copy.sort; testcase svn://svn.kuehne.cn/dstress/run/dup_04.d Thomas
Oct 13 2004