View mode: basic / threaded / horizontal-split · Log in · Help
February 19, 2005
double[].sort doesn't sort
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
February 19, 2005
Re: double[].sort doesn't sort
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>
#18    int compare(void *p1, void *p2)
#19    {
#20	return cast(int)(*cast(double *)p1 - *cast(double *)p2);
#21    }
</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>
February 19, 2005
Re: double[].sort doesn't sort
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
February 19, 2005
Re: double[].sort doesn't sort
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
February 19, 2005
Re: double[].sort doesn't sort
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
February 19, 2005
Re: double[].sort doesn't sort
Sebastian Beschke wrote:
[...]
> didn't fix
[...]

Seems you need to `touch' minit.obj, because it is somehow older than 
minit.asm.

-manfred
February 19, 2005
Re: double[].sort doesn't sort
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
February 20, 2005
Re: double[].sort doesn't sort
"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
February 21, 2005
Re: double[].sort doesn't sort
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?
Top | Discussion index | About this forum | D home