sort error

monarch_dodra monarchdodra at gmail.com
Sat Jun 29 08:35:41 PDT 2013


On Saturday, 29 June 2013 at 14:54:13 UTC, snow wrote:
> On Saturday, 29 June 2013 at 14:20:05 UTC, Ali Çehreli wrote:
>> Not knowing whether it applies to your case, the following is 
>> one almost correct way of writing opCmp:
>>
>>    int opCmp(ref const Vector3D vec) {
>>        return cast(int)(x != vec.x
>>                         ? x - vec.x
>>                         : (y != vec.y
>>                            ? y - vec.y
>>                            : z - vec.z));
>>    }
>>
>> The reason I said "almost" is due to the usual floating point 
>> equality comparison warnings. Values that are supposed to be 
>> equal may not compare equal due to accumulated earlier 
>> floating point calculation errors.
>>
>> Ali
>
> Thats a cool way, thanks. But the exception is still coming.

Not for me, Ali's code works.

> Both solutions  throw -1,0 or 1.

What do you mean "throw -1,0 or 1" ?

> So my first solution should work, too. Sure that the exception 
> is coming, because of the compare function?

Your code throws an exception for me, ali's doesn't. The only 
difference is the compare function. So *pretty* much sure, yes.

That said, in debug code, there *should* be an assert rather than 
a dumb range error. This requires an enhancement.


More information about the Digitalmars-d-learn mailing list