www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - double[].sort doesn't sort

reply Sebastian Beschke <s.beschke gmx.de> writes:
Hi,

I'm trying to sort an array of doubles. Before sorting, it contains 
these values:

0  1  0.5  0.333333  0.666667  0.25  0.5  0.75  0.2  0.4  0.6  0.8

Then I call

	borders.sort;

where borders is the above array. Afterwards the array is:

0.75  1  0.6  0.4  0.2  0.5  0  0.25  0.666667  0.333333  0.5  0.8

In what way is this sorted? I'm afraid I'm not understanding something here.

I'm using dmd 0.113.

Thanks,
Sebastian
Feb 19 2005
parent reply zwang <nehzgnaw gmail.com> writes:
Sebastian Beschke wrote:
 Hi,
 
 I'm trying to sort an array of doubles. Before sorting, it contains 
 these values:
 
 0  1  0.5  0.333333  0.666667  0.25  0.5  0.75  0.2  0.4  0.6  0.8
 
 Then I call
 
     borders.sort;
 
 where borders is the above array. Afterwards the array is:
 
 0.75  1  0.6  0.4  0.2  0.5  0  0.25  0.666667  0.333333  0.5  0.8
 
 In what way is this sorted? I'm afraid I'm not understanding something 
 here.
 
 I'm using dmd 0.113.
 
 Thanks,
 Sebastian
This is due to a bug in phobos/std/typeinfo/ti_double.d. <code> </code> A quick fix: <code> int compare(void *p1, void *p2) { double d = (*cast(double *)p1 - *cast(double *)p2); return d>0?1:d<0?-1:0; } </code>
Feb 19 2005
parent reply Sebastian Beschke <s.beschke gmx.de> writes:
zwang schrieb:
 A quick fix:
 <code>
     int compare(void *p1, void *p2)
     {
         double d = (*cast(double *)p1 - *cast(double *)p2);
     return d>0?1:d<0?-1:0;
     }
 </code>
Thanks, but how do I recompile phobos afterwards? I do C:\dmd\src\phobos>\dm\bin\make -fwin32.mak but it keeps choking on \dm\bin\dmc -c internal\minit.asm masm386 -DM_I386=1 -D_WIN32 -Mx internal\minit.asm; Can't run 'masm386', check PATH Error: '\dm\bin\dmc' not found I even downloaded a "masm386.exe" from somewhere and put it on the PATH, but it still doesn't work. I've never worked with assemblers, I'm afraid ^^ -Sebastian
Feb 19 2005
next sibling parent reply zwang <nehzgnaw gmail.com> writes:
Sebastian Beschke wrote:
 zwang schrieb:
 
 A quick fix:
 <code>
     int compare(void *p1, void *p2)
     {
         double d = (*cast(double *)p1 - *cast(double *)p2);
     return d>0?1:d<0?-1:0;
     }
 </code>
Thanks, but how do I recompile phobos afterwards? I do C:\dmd\src\phobos>\dm\bin\make -fwin32.mak but it keeps choking on \dm\bin\dmc -c internal\minit.asm masm386 -DM_I386=1 -D_WIN32 -Mx internal\minit.asm; Can't run 'masm386', check PATH Error: '\dm\bin\dmc' not found I even downloaded a "masm386.exe" from somewhere and put it on the PATH, but it still doesn't work. I've never worked with assemblers, I'm afraid ^^ -Sebastian
You need to download and install dmc from ftp://ftp.digitalmars.com/dmc.zip
Feb 19 2005
parent reply Sebastian Beschke <s.beschke gmx.de> writes:
zwang schrieb:
 You need to download and install dmc from
 ftp://ftp.digitalmars.com/dmc.zip
I did. It doesn't fix the error. :( -Sebastian
Feb 19 2005
parent reply Manfred Nowak <svv1999 hotmail.com> writes:
Sebastian Beschke wrote:
[...]
 didn't fix
[...] Seems you need to `touch' minit.obj, because it is somehow older than minit.asm. -manfred
Feb 19 2005
parent reply Sebastian Beschke <s.beschke gmx.de> writes:
Manfred Nowak schrieb:
 Seems you need to `touch' minit.obj, because it is somehow older than 
 minit.asm.
Well, it took me some time to find out how to 'touch' in Windows (I used Cygwin in the end -.-), but it finally worked. The sorting bug is also fixed. Thanks Manfred and Zwang. :) -Sebastian
Feb 19 2005
parent "Matthew" <admin stlsoft.dot.dot.dot.dot.org> writes:
"Sebastian Beschke" <s.beschke gmx.de> wrote in message 
news:cv7n28$301d$1 digitaldaemon.com...
 Manfred Nowak schrieb:
 Seems you need to `touch' minit.obj, because it is somehow older than 
 minit.asm.
Well, it took me some time to find out how to 'touch' in Windows
Check out http://shellext.com/
 (I used Cygwin in the end -.-), but it finally worked. The sorting bug 
 is also fixed. Thanks Manfred and Zwang. :)

 -Sebastian 
Feb 19 2005
prev sibling parent Georg Wrede <georg.wrede nospam.org> writes:
Sebastian Beschke wrote:
 zwang schrieb:
 
 A quick fix:
 <code>
     int compare(void *p1, void *p2)
     {
         double d = (*cast(double *)p1 - *cast(double *)p2);
     return d>0?1:d<0?-1:0;
     }
 </code>
Is this on the bug group?
Feb 21 2005